[Python-Dev] Dropping init.py requirement for subpackages (original) (raw)
Phillip J. Eby pje at telecommunity.com
Wed Apr 26 20:11:40 CEST 2006
- Previous message: [Python-Dev] Dropping __init__.py requirement for subpackages
- Next message: [Python-Dev] Dropping __init__.py requirement for subpackages
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 02:07 PM 4/26/2006 -0400, Phillip J. Eby wrote:
def findmodule(self, fullname, path=None): # Note: we ignore 'path' argument since it is only used via metapath subname = fullname.split(".")[-1] if os.path.isdir(os.path.join(self.path, subname)): return self path = [self.path] try: file, filename, etc = imp.findmodule(subname, path) except ImportError: return None return ImpLoader(fullname, file, filename, etc)
Feh. The above won't properly handle the case where there is an init module. Trying again:
def find_module(self, fullname, path=None):
subname = fullname.split(".")[-1]
path = [self.path]
try:
file, filename, etc = imp.find_module(subname, path)
except ImportError:
if os.path.isdir(os.path.join(self.path, subname)):
return self
else:
return None
return ImpLoader(fullname, file, filename, etc)
There, that should only fall back to init-less handling if there's no foo.py or foo/init.py present.
- Previous message: [Python-Dev] Dropping __init__.py requirement for subpackages
- Next message: [Python-Dev] Dropping __init__.py requirement for subpackages
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]