diff options
author | Miro Hrončok <miro@hroncok.cz> | 2021-11-23 15:38:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 15:38:02 (GMT) |
commit | ae1965ccb4b1fad63fab40fe8805d1b8247668d3 (patch) | |
tree | 71db664a46a2804662783d8685a8647f61d14dcf /Doc/library/importlib.rst | |
parent | 8ed1495ad900dd815ff8fb97926da5312aaa23f9 (diff) | |
download | cpython-ae1965ccb4b1fad63fab40fe8805d1b8247668d3.zip cpython-ae1965ccb4b1fad63fab40fe8805d1b8247668d3.tar.gz cpython-ae1965ccb4b1fad63fab40fe8805d1b8247668d3.tar.bz2 |
bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_ca… (GH-29384)
Consider the following directory structure:
.
└── PATH1
└── namespace
└── sub1
└── __init__.py
And both PATH1 and PATH2 in sys path:
$ PYTHONPATH=PATH1:PATH2 python3.11
>>> import namespace
>>> import namespace.sub1
>>> namespace.__path__
_NamespacePath(['.../PATH1/namespace'])
>>> ...
While this interpreter still runs, PATH2/namespace/sub2 is created:
.
├── PATH1
│ └── namespace
│ └── sub1
│ └── __init__.py
└── PATH2
└── namespace
└── sub2
└── __init__.py
The newly created module cannot be imported:
>>> ...
>>> namespace.__path__
_NamespacePath(['.../PATH1/namespace'])
>>> import namespace.sub2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'namespace.sub2'
Calling importlib.invalidate_caches() now newly allows to import it:
>>> import importlib
>>> importlib.invalidate_caches()
>>> namespace.__path__
_NamespacePath(['.../PATH1/namespace'])
>>> import namespace.sub2
>>> namespace.__path__
_NamespacePath(['.../PATH1/namespace', '.../PATH2/namespace'])
This was not previously possible.
Diffstat (limited to 'Doc/library/importlib.rst')
-rw-r--r-- | Doc/library/importlib.rst | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst index 6b71e64..59c8c64 100644 --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -145,6 +145,10 @@ Functions .. versionadded:: 3.3 + .. versionchanged:: 3.10 + Namespace packages created/installed in a different :data:`sys.path` + location after the same namespace was already imported are noticed. + .. function:: reload(module) Reload a previously imported *module*. The argument must be a module object, |