[Python-Dev] Draft PEP: "Simplified Package Layout and Partitioning"

Nick Coghlan ncoghlan at gmail.com
Fri Jul 22 02:58:20 CEST 2011

On Fri, Jul 22, 2011 at 10:00 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Wouldn't it produce confusing situations like the above example?

I don't see how it is any more confusing than any other form of module

For backwards compatibility reasons, the precedence model will be:

1. Modules and self-contained packages that can satisfy the import
request are checked for first (along the whole length of sys.path).
2. If that fails, the virtual package mechanism is checked

PEP 402 eliminates some cases of package shadowing by making
__init__.py files optional, so your scenario will actually *work*, so
long as the submodule name doesn't conflict with a module attribute.

*Today* if you have:


in the same sys.path directory, x.py wins (search order is controlled
by the internal order of checks within the import system - and source
files are first on that list).

With PEP 302, x.py still wins, but the submodules within the x
directory become accessible so long as they don't conflict with
*actual* attributes set in the x module.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list