cpython/Lib/test/test_importlib
Miro Hrončok ae1965ccb4
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.
2021-11-23 07:38:02 -08:00
..
builtin
data
data01
data02
data03
extension
frozen bpo-21736: Set __file__ on frozen stdlib modules. (gh-28656) 2021-10-14 15:32:18 -06:00
import_
namespace_pkgs
namespacedata01
partial
resources
source [codemod] Fix non-matching bracket pairs (GH-28473) 2021-09-22 01:09:00 +02:00
zipdata01
zipdata02
__init__.py
__main__.py
abc.py
fixtures.py
stubs.py
test_abc.py
test_api.py
test_compatibilty_files.py
test_contents.py
test_files.py
test_lazy.py
test_locks.py bpo-45229: Remove test_main in many tests (GH-28405) 2021-09-19 15:27:33 +03:00
test_main.py
test_metadata_api.py
test_namespace_pkgs.py bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_ca… (GH-29384) 2021-11-23 07:38:02 -08:00
test_open.py
test_path.py
test_pkg_import.py
test_read.py
test_reader.py
test_resource.py
test_spec.py
test_threaded_import.py bpo-45229: Remove test_main in many tests (GH-28405) 2021-09-19 15:27:33 +03:00
test_util.py
test_windows.py
test_zip.py
threaded_import_hangers.py
update-zips.py
util.py