cpython/Python
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
..
clinic
_warnings.c [3.9] bpo-40998: Fix a refleak in create_filter() (GH-23365) (GH-23369) 2020-11-18 09:45:29 -08:00
asdl.c
ast.c [3.9] bpo-45461: Fix IncrementalDecoder and StreamReader in the "unicode-escape" codec (GH-28939) (GH-28945) 2021-10-14 20:03:29 +03:00
ast_opt.c
ast_unparse.c
bltinmodule.c bpo-44856: Possible reference leak in error paths of update_bases() and __build_class__ (GH-27647) (GH-27651) 2021-08-07 13:17:41 +02:00
bootstrap_hash.c [3.9] Remove trailing spaces (GH-28710) 2021-10-03 20:04:38 +03:00
ceval.c [3.9] bpo-45806: Fix recovery from stack overflow for 3.9. Again. (GH-29640) 2021-11-19 19:51:50 +01:00
ceval_gil.h
codecs.c
compile.c Set line number of END_ASYNC_FOR so that it doesn't show in traces. (GH-27255) 2021-07-20 12:09:56 +02:00
condvar.h
context.c
dtoa.c
dup2.c
dynamic_annotations.c
dynload_aix.c bpo-41894: Fix UnicodeDecodeError while loading native module (GH-22466) 2020-10-14 19:25:45 -07:00
dynload_dl.c
dynload_hpux.c bpo-44959: Add fallback to extension modules with '.sl' suffix on HP-UX (GH-27857) 2021-10-22 04:08:50 -07:00
dynload_shlib.c bpo-41894: Fix UnicodeDecodeError while loading native module (GH-22466) 2020-10-14 19:25:45 -07:00
dynload_stub.c
dynload_win.c bpo-43499: Silence compiler warnings about using legacy C API on Windows (GH-24873) 2021-03-16 08:03:37 +02:00
errors.c [3.9] bpo-45806: Fix recovery from stack overflow for 3.9. Again. (GH-29640) 2021-11-19 19:51:50 +01:00
fileutils.c [3.9] Fix typos in the Python directory (GH-28767) (GH-28798) 2021-10-07 07:36:39 -07:00
formatter_unicode.c bpo-28146: Fix a confusing error message in str.format() (GH-24213) 2021-05-13 14:35:30 -07:00
frozen.c
frozenmain.c
future.c
getargs.c bpo-36346: Add Py_DEPRECATED to deprecated unicode APIs (GH-20878) 2020-06-18 17:30:53 +09:00
getcompiler.c
getcopyright.c Update copyright year to 2022. (GH-30335) 2022-01-02 12:34:36 -08:00
getopt.c
getplatform.c
getversion.c
graminit.c
hamt.c
hashtable.c bpo-41061: Fix incorrect expressions in hashtable (GH-21028) 2020-06-22 01:01:48 -07:00
import.c [3.9] bpo-44050: Extension modules can share state when they don't support sub-interpreters. (GH-27794) (GH-28741) 2021-10-05 22:30:25 +02:00
importdl.c Fix format string in _PyImport_LoadDynamicModuleWithSpec() (GH-28863) 2021-10-12 10:10:41 -07:00
importdl.h
importlib.h [3.9] bpo-41076: Pre-feed the parser with the f-string expression location (GH-21054) (GH-21190) 2020-06-28 01:15:28 +01:00
importlib_external.h [3.9] bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_cache (GH-29384) (GH-30922) (GH-31076) 2022-02-02 05:50:43 -08:00
importlib_zipimport.h
initconfig.c [3.9] Fix typos in the Python directory (GH-28767) (GH-28798) 2021-10-07 07:36:39 -07:00
makeopcodetargets.py
marshal.c bpo-41180: Replace marshal code.__new__ audit event with marshal.load[s] and marshal.dumps (GH-26971) 2021-06-30 18:52:39 +01:00
modsupport.c closes bpo-41533: Fix a potential memory leak when allocating a stack (GH-21847) 2020-09-04 15:56:04 -07:00
mysnprintf.c bpo-36020: Remove snprintf macro in pyerrors.h (GH-20889) 2020-06-15 13:20:10 -07:00
mystrtoul.c
opcode_targets.h
pathconfig.c [3.9] Fix typos in the Python directory (GH-28767) (GH-28798) 2021-10-07 07:36:39 -07:00
peephole.c bpo-42057: Fix peephole optimizer (GH-22802) 2020-10-22 11:06:07 +09:00
preconfig.c
pyarena.c
pyctype.c
pyfpe.c
pyhash.c
pylifecycle.c bpo-40998: Address compiler warnings found by ubsan (GH-20929) 2020-11-18 08:01:48 -08:00
pymath.c
pystate.c [3.9] bpo-42540: reallocation of id_mutex should not force default allocator (GH-29564) (GH-29600) 2021-11-17 23:53:33 +01:00
pystrcmp.c bpo-41524: fix pointer bug in PyOS_mystr{n}icmp (GH-21845) (GH-21978) 2020-08-30 15:53:09 +09:00
pystrhex.c
pystrtod.c
Python-ast.c [3.9] bpo-11105: Do not crash when compiling recursive ASTs (GH-20594) (GH-26522) 2021-06-03 22:22:34 +01:00
pythonrun.c bpo-45614: Fix traceback display for exceptions with invalid module name (GH-29726) (GH-29827) 2021-11-29 10:11:48 +00:00
pytime.c [3.9] Remove trailing spaces (GH-28710) 2021-10-03 20:04:38 +03:00
README
strdup.c
structmember.c
symtable.c
sysmodule.c [3.9] bpo-45806: Fix recovery from stack overflow for 3.9. Again. (GH-29640) 2021-11-19 19:51:50 +01:00
thread.c
thread_nt.h bpo-41299: Reduce lag in Windows threading timeouts by using a higher precision time source (GH-26568) 2021-06-11 15:03:10 -07:00
thread_pthread.h bpo-41710: PyThread_acquire_lock_timed() uses sem_clockwait() (GH-28671) (GH-28683) 2021-10-01 18:51:15 +02:00
traceback.c bpo-45831: _Py_DumpASCII() uses a single write() call if possible (GH-29596) (GH-29597) 2021-11-17 22:59:42 +01:00
wordcode_helpers.h

Miscellaneous source files for the main Python shared library