[Python-Dev] Dropping __init__.py requirement for subpackages

"Martin v. Löwis" martin at v.loewis.de
Wed Apr 26 22:27:19 CEST 2006


Phillip J. Eby wrote:
>> I assume you want
>>
>> import x.y
>>
>> to fail if y is an empty directory (or non-empty, but without .py
>> files). I don't see a value in implementing such a restriction.
> 
> No, I'm saying that tools which are looking for packages and asking, "Is
> this directory a package?" should decide "no" in the case where it
> contains no modules.

Ah. Tools are of course free to do that. It would slightly deviate
from Python's implementation of import, but the difference wouldn't
matter for all practical purposes.

So from a language lawyers' point of view, I would specify:

"A sub-package is a sub-directory of a package that contains at least
one module file. Python implementations MAY accept sub-directories
as sub-packages even if they contain no module files as package, instead
of raising ImportError on attempts to import that sub-package."

(a module file, in that context, would be a file file which matches
imp.get_suffixes(), in case that isn't clear)

Regards,
Martin


More information about the Python-Dev mailing list