[Import-SIG] New PEP draft: "Simplified Package Layout and Partitioning"

P.J. Eby pje at telecommunity.com
Wed Aug 17 22:53:01 CEST 2011

At 01:24 PM 8/17/2011 +1000, Nick Coghlan wrote:
>With PEP 402, for the backwards compatibility reasons described in the
>PEP, we need to distinguish the 'parent imports' from direct imports,
>so we can ignore pure virtual packages in the latter case. However,
>the further special casing to say 'only load the pure virtual packages
>if the child module is found' seems like a needless complication. We
>may end up with childless virtual packages in sys.modules *anyway* due
>to failures in the load stage, so what's the advantage of avoiding
>creating them just because the subsequent failure happened to occur in
>the find stage?

You might be right.  My concern, though, is that whenever you try to 
import a non-existent module, you'll be adding its parents to 
sys.modules -- something that doesn't happen right now, because the 
import fails as soon as the parent isn't found.

IOW, right now if I import foo.bar.baz, and there's no "foo", nothing 
gets added to sys.modules.  Under PEP 402 without lazy module 
creation, you'd end up with an emtpy 'foo' pointing to 'bar', and an 
empty 'foo.bar' module, despite the possible non-existence of these packages.

Sure, if the module load fails, you'll still have the parents...  but 
in that instance, you at least have an assurance that the parents are "real".

More information about the Import-SIG mailing list