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 9ac0e87
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions immutabledict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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 stored the cached hash value when pickling
# as the value might change across Python invocations.
return (self.__class__, (self._dict,))

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

Expand Down

0 comments on commit 9ac0e87

Please sign in to comment.