Re: Dabeaz's weird import discovery
Eric Snow <[email protected]> Wed, 22 Apr 2015 11:54:35 -0600
| Newsgroups | gmane.comp.python.import |
|---|---|
| Message-ID | <CALFfu7BuESkXZMF=SESUSWpJuH1KMhAzows0oyLxXZNt3MRb3Q@mail.gmail.com> |
On Wed, Apr 22, 2015 at 11:37 AM, Guido van Rossum <[email protected]> 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 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. :) -eric