diff --git a/immutabledict/__init__.py b/immutabledict/__init__.py index 152ce4e..71f905a 100644 --- a/immutabledict/__init__.py +++ b/immutabledict/__init__.py @@ -11,6 +11,7 @@ KeysView, Mapping, Optional, + Tuple, Type, TypeVar, ValuesView, @@ -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,)) + def __getitem__(self, key: _K) -> _V: return self._dict[key]