Re: Dabeaz's weird import discovery

Barry Warsaw <[email protected]> Wed, 22 Apr 2015 13:52:40 -0400
Newsgroups gmane.comp.python.import
Organization Damn Crazy Followers of the Horn
Message-ID <[email protected]>
On Apr 22, 2015, at 10:37 AM, Guido van Rossum wrote:

>On Wed, Apr 22, 2015 at 10:33 AM, Eric Snow <[email protected]>
>wrote:
>> 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
>> also
>> > 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
sense.

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.

Cheers,
-Barry

_______________________________________________
Import-SIG mailing list
[email protected]
https://mail.python.org/mailman/listinfo/import-sig
signature.asc (application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJVN9/pAAoJEBJutWOnSwa/XqIQAIMTmR8qY8fdVO0B9jfPtH4z
s/vMXGHDwsNJ1r0EqNzP1UeCR9PNoqCsaMTRbyntxTU0nMgng79uuacaiJ/rnzXg
IqBXJARCXn3dW4fO2bSG3ac9XmoaG3xgzYIYRgW+jM2rfShZoX9w9d3+Z/xndgEL
cC/Mc4AQrM05Ur5jhpUlULWPtxnnAY1q/U76Ft+F9p/KUHvQcQkgZuB0RacEoCxc
5LZUldWT3gzRyBpUju0rVjvIB3MM2JFN8er4Fi4yLTih9LAsFQH3qfqvbxVHxYC5
jCDgWCci+5L0XQq1BszothEYURl7ag0/2y8rsdscvmTXtGkfRZee/82NQeOLuYLG
JIs3DKJSpPXoP+8U4H8FblD1IfM6RlPAMzzifCKBA1TdE3CEfQO/m/fFFCSkUF0Y
vcsR/OC4fkdWpOwEvEC6PA+OPYVhNYVlonj2F6x4Q0zpKQpqlwrEGGuxCZqbegHy
4q/1O5LTU7YqxQn5+YKw0BJLSIPOvuQZjBwiHQM1TMbU1m32sY59A4cnIt2CB12s
3gn5TifyOVwa2sQ86eV9XFRkK40IleDNB0UoTlcrlOWN2crZgpQctWDkf355CI3F
hLb6FzNW53D9NkooCs4zjn9yLbXCV6jIRgEKHSKRH7STO5HvWd7tr6jNtvPu+k91
5l/e7VzjlN8NUr+Ow7f1
=T4Pf
-----END PGP SIGNATURE-----