[issue45183] Unexpected exception with zip importer

Ronald Oussoren report at bugs.python.org
Thu Sep 16 06:44:35 EDT 2021


Ronald Oussoren <ronaldoussoren at mac.com> added the comment:

I just noticed that I'm unnecessarily obtuse in my description of a possible fix, the diff (without test update):

% git diff Lib/zipimport.py                                                                                        (main)cpython
diff --git a/Lib/zipimport.py b/Lib/zipimport.py
index c55fec6aa1..43ac6cbe57 100644
--- a/Lib/zipimport.py
+++ b/Lib/zipimport.py
@@ -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):


With that change the exception should not happen, and the now stale zipimporter would be ignored when flushing the cache while the zipfile referenced by the zip importer instance has been removed.

That said, I haven't tested this and won't create a PR because my local tree is (still) a mess.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45183>
_______________________________________


More information about the Python-bugs-list mailing list