<div class="gmail_quote">On Mon, Mar 12, 2012 at 11:49 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">So the only backwards incompatibility is that "import foo" may succeed<br></div>
where it previously failed if there is a directory foo/ somewhere on<br>
sys.path but no foo.py and no foo/__init__.py anywhere. I don't think<br>
this is a big deal.<br></blockquote><div><br></div><div>Actually, it *is* a big deal. An early draft of PEP 402 was like the newly-proposed approach, and it was shot down by an *actual code sample from a real package* that somebody posted to show the problem. The motivating example is actually presented in the PEP: trying to "import json" with a json/ directory present -- and the "json" package *not* present -- and then trying to use its contents. The PEP works around this by taking the namespace concept to its logical extreme and saying you can only import the *contents* of the namespace, because the namespace itself doesn't exist. (i.e., it's virtual.)</div>
<div><br></div><div>tl;dr version: the killer problem with allowing "import foo" to succeed is that code which does try/except ImportError to test for a package's presence will get false positives. That's the motivating reason for only allowing sub-namespace package imports to succeed: it prevents the immediate breakage of real code, the moment the feature is introduced. :-(</div>
</div>