summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <brettcannon@users.noreply.github.com>2018-04-06 23:10:18 (GMT)
committerGitHub <noreply@github.com>2018-04-06 23:10:18 (GMT)
commit9e2be60634914f23db2ae5624e4acc9335bf5fea (patch)
tree9b1613b2c8bdad0fd942222c07a72e90e8dd509e /Lib/importlib
parent3a9ccee0e5dbf7d67f5ab79f6095755969db117c (diff)
downloadcpython-9e2be60634914f23db2ae5624e4acc9335bf5fea.zip
cpython-9e2be60634914f23db2ae5624e4acc9335bf5fea.tar.gz
cpython-9e2be60634914f23db2ae5624e4acc9335bf5fea.tar.bz2
bpo-33169: Remove values of `None` from sys.path_importer_cache when invalidating caches (GH-6402)
An entry of None in sys.path_importer_cache represents a negative/missing finder for a path, so clearing it out makes sense.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap_external.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 420ecc8..da9a75c 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -1181,8 +1181,10 @@ class PathFinder:
def invalidate_caches(cls):
"""Call the invalidate_caches() method on all path entry finders
stored in sys.path_importer_caches (where implemented)."""
- for finder in sys.path_importer_cache.values():
- if hasattr(finder, 'invalidate_caches'):
+ for name, finder in list(sys.path_importer_cache.items()):
+ if finder is None:
+ del sys.path_importer_cache[name]
+ elif hasattr(finder, 'invalidate_caches'):
finder.invalidate_caches()
@classmethod