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

Phillip J. Eby pje at telecommunity.com
Wed Apr 26 22:52:33 CEST 2006


At 04:33 PM 4/26/2006 -0400, Joe Smith wrote:
>It seems to me that the right way to fix this is to simply make a small
>change to the error message.
>On a failed import, have the code check if there is a directory that would
>have been  the requested package if
>it had contained an __init__ module. If there is then append a message like
>"You might be missing an __init__.py file".
>
>It might also be good to check that the directory actually contained python
>modules.

This is a great idea, but might be hard to implement in practice with the 
current C implementation of import, at least for the general case.

But if we're talking about subpackages only, the common case is a 
one-element __path__, and for that case there might be something we could do.

(The number of path items is relevant because the existence of a 
correctly-named but init-less directory should not stop later path items 
from being searched, so the actual "error" occurs far from the point where 
the empty directory would've been detected.)



More information about the Python-Dev mailing list