[Import-SIG] Dabeaz's weird import discovery
barry at python.org
Wed Apr 22 19:52:40 CEST 2015
On Apr 22, 2015, at 10:37 AM, Guido van Rossum wrote:
>On Wed, Apr 22, 2015 at 10:33 AM, Eric Snow <ericsnowcurrently at gmail.com>
>> The surprising part is that it also happens for explicit relative
>> imports. I'm guessing that part was unintentional and simply not
>> noticed when PEP 328 was implemented.
>No, that must also have been intentional, because even when you use
>relative import, the module you imported knows its full name, and that full
>name is used as its key in sys.modules. If someone else uses absolute
>import for the same module they should still get the same module object.
>> > I guess another thing to realize is that the globals of __init__.py are
>> > the attribute namespace of the package.
>> Do you think this is confusing for anyone? It seems obvious to me,
>> but I'm pretty familiar with the import system. :)
>When you look at it from a different angle it's totally obvious. But
>apparently it surprised Dave and Barry.
No, that part I get. I remember the discussions around this back in the
Pythonlabs days. :)
The surprising part was the effect of explicit relative imports on the
namespace of the parent, but given your explanation above, it now makes
It's still surprising given Python's other name binding rules. Maybe as
surprising (to some) that "import os" magically gives you "os.path" :).
It'll be easy to document though.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 819 bytes
Desc: OpenPGP digital signature
More information about the Import-SIG