Skip to content

Commit

Permalink
Make zipp.compat.overlay.zipfile hashable.
Browse files Browse the repository at this point in the history
Closes #126
  • Loading branch information
jaraco committed Sep 13, 2024
1 parent d66007a commit a4c7961
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/126.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make zipp.compat.overlay.zipfile hashable.
13 changes: 12 additions & 1 deletion zipp/compat/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
Relative imports are supported too.
>>> from zipp.compat.overlay.zipfile import ZipInfo
The ``zipfile`` object added to ``sys.modules`` needs to be
hashable (#126).
>>> hash(sys.modules['zipp.compat.overlay.zipfile']) > 0
True
"""

import importlib
Expand All @@ -20,7 +26,12 @@
import zipp


zipfile = types.SimpleNamespace(**vars(importlib.import_module('zipfile')))
class HashableNamespace(types.SimpleNamespace):
def __hash__(self):
return hash(tuple(vars(self)))


zipfile = HashableNamespace(**vars(importlib.import_module('zipfile')))
zipfile.Path = zipp.Path
zipfile._path = zipp

Expand Down

0 comments on commit a4c7961

Please sign in to comment.