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.
This commit is contained in:
Brett Cannon 2018-04-06 16:10:18 -07:00 committed by GitHub
parent 3a9ccee0e5
commit 9e2be60634
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 652 additions and 620 deletions

View file

@ -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