[Python-ideas] Idea: Importing from arbitrary filenames

Paul Moore p.f.moore at gmail.com
Mon Apr 16 12:36:46 EDT 2018


On 16 April 2018 at 17:22, Nick Coghlan <ncoghlan at gmail.com> wrote:
> If we're not covering explicit __path__ manipulation anywhere, we
> should definitely mention that possibility.
> https://docs.python.org/3/library/pkgutil.html#pkgutil.extend_path
> does talk about it, but only in the context of scanning sys.path for
> matching names, not in the context of building a package from an
> arbitrary set of directory names.

It's quite possible that we're not.

> I'm not sure where we could put an explanation of some of the broader
> implications of that fact, though - while __path__ manipulation is
> usually fairly safe, we're always a little hesitant about encouraging
> too many dynamic modifications to the import system state, since it
> can sometimes have odd side effects based on whether imports happen
> before or after that state is adjusted..

One of the problems with PEP 302 was that there was no really good
place in the documentation to put all the information that was present
(certainly not in the version of the docs that was around when we
wrote it). So a lot of the important details remained buried in PEP
302. Since then, a lot of the details ended up in the docs, mostly in
the importlib sections, but I don't recall ever seeing anything about
__path__ (and particularly not the nice summary you gave, "packages
are ultimately just modules with a
__path__ attribute that works like sys.path".

Paul


More information about the Python-ideas mailing list