Open mlucool opened 4 years ago
Hi,
In python 3, FrozenDict can be pickled, but not unpickled (python2 does not have this issue):
FrozenDict
$ python3 -c 'from vdom.frozendict import FrozenDict; from six.moves import cPickle; cPickle.loads(cPickle.dumps(FrozenDict(a=1), -1))' Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/local/python/python-3.7/std/lib64/python3.7/site-packages/vdom/frozendict.py", line 26, in __setitem__ return self.__readonly__(super(FrozenDict, self).__setitem__, *args, **kwargs) File "/usr/local/python/python-3.7/std/lib64/python3.7/site-packages/vdom/frozendict.py", line 21, in __readonly__ raise ValueError("Can not modify FrozenDict") ValueError: Can not modify FrozenDict
I believe this is due to the reduce method. For example, this fixes it:
from vdom.frozendict import FrozenDict def _reduce_vdom_frozendict(self): return (FrozenDict, (tuple(self.items()),)) FrozenDict.__reduce__ = _reduce_vdom_frozendict
I am happy to make a PR if you believe this is the right fix.
Bumping this as we still run into it sometimes. Would you be willing to accept a PR for this?
CC @captainsafia @rgbkrk @willingc
Hi,
In python 3,
FrozenDict
can be pickled, but not unpickled (python2 does not have this issue):I believe this is due to the reduce method. For example, this fixes it:
I am happy to make a PR if you believe this is the right fix.