Skip to content

Commit

Permalink
Do not store cached hash value when pickling
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasdiener committed Dec 6, 2023
1 parent c9504d0 commit f3ca52d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions immutabledict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
KeysView,
Mapping,
Optional,
Tuple,
Type,
TypeVar,
ValuesView,
Expand Down Expand Up @@ -45,6 +46,11 @@ def __new__(cls, *args: Any, **kwargs: Any) -> immutabledict[_K, _V]: # noqa: D
setattr(inst, "_hash", None)
return inst

def __reduce__(self) -> Tuple[Any, ...]:
# Do not store the cached hash value when pickling
# as the value might change across Python invocations.
return (self.__class__, (self._dict,))

Check warning on line 52 in immutabledict/__init__.py

View check run for this annotation

Codecov / codecov/patch

immutabledict/__init__.py#L52

Added line #L52 was not covered by tests

def __getitem__(self, key: _K) -> _V:
return self._dict[key]

Expand Down

0 comments on commit f3ca52d

Please sign in to comment.