Petr Viktorin
|
8d239bfdcc
|
[3.9] bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_cache (GH-29384) (GH-30922) (GH-31076)
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.
Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
Automerge-Triggered-By: GH:encukou
|
2022-02-02 05:50:43 -08:00 |
|
Anthony Sottile
|
ab9b31f947
|
bpo-35843: Implement __getitem__ for _NamespacePath (GH-11690)
|
2019-03-08 10:58:00 -08:00 |
|
Barry Warsaw
|
bbbcf8693b
|
bpo-32303 - Consistency fixes for namespace loaders (#5481)
* Make sure ``__spec__.loader`` matches ``__loader__`` for namespace packages.
* Make sure ``__spec__.origin` matches ``__file__`` for namespace packages.
https://bugs.python.org/issue32303
https://bugs.python.org/issue32305
|
2018-02-02 15:15:58 -05:00 |
|
Eric Snow
|
d65018b17c
|
Fixes #19711: Add tests for reloading namespace packages.
|
2016-05-10 15:29:05 -06:00 |
|
Serhiy Storchaka
|
e437a10d15
|
Issue #23277: Remove unused imports in tests.
|
2016-04-24 21:41:02 +03:00 |
|
Serhiy Storchaka
|
597d15afe4
|
Issue #23277: Remove unused support.run_unittest import.
|
2016-04-24 13:45:58 +03:00 |
|
Eric Snow
|
c4bbd7a492
|
Issue #21097: Move test_namespace_pkgs into test_importlib.
|
2014-03-29 15:57:44 -06:00 |
|