I am trying to add pickle support to the classes made by the editabletuple’s editabletuple
and editableobject
functions. (source code.)
I read the docs and tried adding these two functions:
def __getstate__(self):
return self.asdict # a property that returns key/values for the object's slots (it has no dict)
def __setstate__(self, state):
self.update(**state)
These were added to the class’s constructing type()
call:
attributes = dict(
__init__=__init__, asdict=property(asdict),
astuple=property(astuple), update=update, _update=_update,
__repr__=__repr__, __delattr__=__delattr__, __setattr__=__setattr__,
_defaults=defaults, _validator=staticmethod(validator),
__eq__=__eq__, __lt__=__lt__, __slots__=fieldnames, __doc__=doc,
__getstate__=__getstate__, __setstate__=__setstate__)
return functools.total_ordering(type(classname, (), attributes))
But with them or without them, I get the same error:
_pickle.PicklingError: Can't pickle <class 'editabletuple.Point'>: attribute lookup Point on editabletuple failed
_pickle.PicklingError: Can't pickle <class '__main__.Point'>: attribute lookup Point on __main__ failed
The first error is when I try putting pickling an editabletuple interactively in IDLE, the second when I try it in an editabletuple doctest.