cpython/Lib/test/test_importlib
Petr Viktorin 5c39e474db
[3.10] bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_cache (GH-29384) (GH-30922)
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.
2022-01-27 06:00:23 -08:00
..
builtin
data
data01
data02
data03
extension
frozen
import_
namespace_pkgs
namespacedata01
partial
source [3.10] [codemod] Fix non-matching bracket pairs (GH-28473) (GH-28511) 2021-09-22 01:33:59 +02:00
zipdata01
zipdata02
__init__.py
__main__.py
abc.py
fixtures.py
stubs.py
test_abc.py
test_api.py
test_files.py
test_lazy.py
test_locks.py [3.10] bpo-45229: Remove test_main in many tests (GH-28405) (GH-28455) 2021-09-19 22:36:03 +03:00
test_main.py
test_metadata_api.py bpo-46105: Honor spec when generating requirement specs with urls and extras. (GH-30151) 2021-12-16 13:19:14 -08:00
test_namespace_pkgs.py [3.10] bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_cache (GH-29384) (GH-30922) 2022-01-27 06:00:23 -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 [3.10] bpo-45229: Remove test_main in many tests (GH-28405) (GH-28455) 2021-09-19 22:36:03 +03:00
test_util.py Python 3.10.0rc1 2021-08-02 20:53:59 +01:00
test_windows.py
test_zip.py
threaded_import_hangers.py
update-zips.py
util.py