How to add pickle support to editable{tuple,object}

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.

For some reason I can’t edit the title or text of the original post.

Rather hoping that a more advanced Python programmer would be able to give me some hints/help with this?

Basically, the editable tuple module provides two functions, editabletuple and editableobject which both return classes (like namedtuple does). But I want instances of the classes thus created to be pickleable, but can’t figure out how to do it.

Yeah, it’s time limited: I can edit the ‘Topic’ title for you (as can other members with that privilege), if that’s what you want, but I can’t edit your posts.

That’s okay: I’ve forgotten what I hoped to change it to, I guess to make it more appealilng to an advanced poster. Anyway, I’m just hoping someone can help :smiley: