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 bpo-42135: Deprecate implementations of find_module() and find_loader() (GH-25169) 2021-04-06 08:56:57 -07:00
data
data01
data02
data03
extension bpo-42135: Deprecate implementations of find_module() and find_loader() (GH-25169) 2021-04-06 08:56:57 -07:00
frozen bpo-21736: Set __file__ on frozen stdlib modules. (gh-28656) 2021-10-14 15:32:18 -06:00
import_ bpo-42135: Deprecate implementations of find_module() and find_loader() (GH-25169) 2021-04-06 08:56:57 -07:00
namespace_pkgs
namespacedata01 bpo-42129: Add support for resources in namespaces (GH-24670) 2021-03-04 13:43:00 -05:00
partial bpo-43517: Fix false positive in detection of circular imports (#24895) 2021-03-20 20:07:44 +01:00
resources bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436) 2021-07-29 21:05:05 -04:00
source [codemod] Fix non-matching bracket pairs (GH-28473) 2021-09-22 01:09:00 +02:00
zipdata01 bpo-42129: Add support for resources in namespaces (GH-24670) 2021-03-04 13:43:00 -05:00
zipdata02 bpo-42129: Add support for resources in namespaces (GH-24670) 2021-03-04 13:43:00 -05:00
__init__.py
__main__.py
abc.py
fixtures.py bpo-43926: Cleaner metadata with PEP 566 JSON support. (GH-25565) 2021-05-02 17:03:40 -04:00
stubs.py bpo-39595: Improve zipfile.Path performance (#18406) 2020-02-11 21:58:47 -05:00
test_abc.py bpo-42135: Deprecate implementations of find_module() and find_loader() (GH-25169) 2021-04-06 08:56:57 -07:00
test_api.py bpo-42135: Deprecate implementations of find_module() and find_loader() (GH-25169) 2021-04-06 08:56:57 -07:00
test_compatibilty_files.py bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436) 2021-07-29 21:05:05 -04:00
test_contents.py bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436) 2021-07-29 21:05:05 -04:00
test_files.py bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436) 2021-07-29 21:05:05 -04:00
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 bpo-43926: Cleaner metadata with PEP 566 JSON support. (GH-25565) 2021-05-02 17:03:40 -04:00
test_metadata_api.py bpo-44784: Apply changes from importlib_metadata 4.6.3 (GH-27508) 2021-07-31 06:08:13 -07:00
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 bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436) 2021-07-29 21:05:05 -04:00
test_path.py bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436) 2021-07-29 21:05:05 -04:00
test_pkg_import.py bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25181) 2021-04-05 13:11:23 +09:00
test_read.py bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436) 2021-07-29 21:05:05 -04:00
test_reader.py bpo-38693: Prefer f-strings in importlib.resources (importlib_resources 5.0.6). (GH-26387) 2021-05-26 13:16:11 -07:00
test_resource.py bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436) 2021-07-29 21:05:05 -04:00
test_spec.py bpo-43105: Importlib now resolves relative paths when creating module spec objects from file locations (GH-25121) 2021-04-07 01:02:07 +01:00
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 bpo-43672: raise ImportWarning when calling find_loader() (GH-25119) 2021-04-02 12:35:32 -07:00
test_windows.py bpo-43864: Silence deprecation warning in test_importlib.test_module_found and test_importlib.test_module_not_found (GH-25656) 2021-04-27 16:56:08 +01:00
test_zip.py bpo-44246: Entry points performance improvements. (GH-26467) 2021-05-31 11:52:29 -04:00
threaded_import_hangers.py
update-zips.py bpo-42129: Add support for resources in namespaces (GH-24670) 2021-03-04 13:43:00 -05:00
util.py bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436) 2021-07-29 21:05:05 -04:00