[Import-SIG] Dabeaz's weird import discovery

Eric Snow ericsnowcurrently at gmail.com
Wed Apr 22 19:54:35 CEST 2015

On Wed, Apr 22, 2015 at 11:37 AM, Guido van Rossum <guido at python.org> wrote:
> On Wed, Apr 22, 2015 at 10:33 AM, Eric Snow <ericsnowcurrently at gmail.com>
> 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 see what you're saying.  __name__ and sys.modules definitely need to
reflect the fully resolved name.  I just mean that for relative import
there is no need to bind the submodule to the parent, is there?  I'd
consider it a code smell if I saw a module that imports just the
parent and expecting the submodule to be bound there due to an import
in yet another module.  EIBTI.  That's not specific to relative
imports, but it does demonstrate the only case I can think of where
someone might be relying on this behavior of relative imports.  That's
why I think it was unintentional.

Regardless, there's nothing to be done at this point besides document
the behavior. :)


More information about the Import-SIG mailing list