[Python-ideas] Allow multiple imports from a package while preserving its namespace

Eric Snow ericsnowcurrently at gmail.com
Fri Apr 27 12:18:35 EDT 2018


On Fri, Apr 27, 2018 at 5:14 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Taking this idea in a completely different direction: what if we were
> to take advantage of PEP 451 __spec__ attributes to enhance modules to
> natively support implicit on-demand imports before they give up and
> raise AttributeError? (Essentially making all submodule imports
> implicitly lazy if you don't explicitly import them - you'd only be
> *required* to explicitly import top level modules, with everything
> under that being an implementation detail of that top level package)

That might be interesting to explore.  It smells like something
related to the lazy import magic that Neil Shemenauer is working on.

On the plus side, it means one less thing for programmers to do.  On
the minus side, I find the imports at the top of the file to be a nice
catalog of external dependencies.  Implicitly importing submodules
would break that.

The idea might be not as useful since the programmer would have to use
the fully qualified name (relative to the "top-level" package).  So
why not just put that in the import statement?

-eric


More information about the Python-ideas mailing list