Skip to content

[3.10] bpo-45183: don't raise an exception when calling zipimport.zipimporter.find_spec() when the zip file is missing and the internal cache has been reset (GH-28435) #28437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/test/test_zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,9 @@ def testInvalidateCaches(self):
# Check that the cached data is removed if the file is deleted
os.remove(TEMP_ZIP)
zi.invalidate_caches()
self.assertIsNone(zi._files)
self.assertFalse(zi._files)
self.assertIsNone(zipimport._zip_directory_cache.get(zi.archive))
self.assertIsNone(zi.find_spec("name_does_not_matter"))

def testZipImporterMethodsInSubDirectory(self):
packdir = TESTPACK + os.sep
Expand Down
2 changes: 1 addition & 1 deletion Lib/zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def invalidate_caches(self):
_zip_directory_cache[self.archive] = self._files
except ZipImportError:
_zip_directory_cache.pop(self.archive, None)
self._files = None
self._files = {}


def __repr__(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Have zipimport.zipimporter.find_spec() not raise an exception when the underlying zip
file has been deleted and the internal cache has been reset via
invalidate_cache().