From e1bdecb6dc7ac33256d5fa875d45634512d2a90e Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 17 Sep 2021 17:46:22 -0700 Subject: [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) (#28438) This can occur when the zip file gets deleted, you call zipimport.zipimporter.invalidate_cache(), and then try to use zipimport.zipimporter.find_spec() (i.e. you left the zip file path on sys.path). (cherry picked from commit 209b7035f714dcc41df054b0b023e0b955d7e1a2) Co-authored-by: Brett Cannon --- Lib/test/test_zipimport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Lib/test') diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py index f6f5ca4adc..8acfeef274 100644 --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -547,8 +547,9 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): # 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 -- cgit v1.2.1