Angus Hollands writes:

 > yes I'd pass in some kind of 'old' object as a proxy to the old object
 > state.

Mostly you shouldn't need to do this, you can copy the state:

    def method(self, args):
        import copy
        old = copy.deepcopy(self)

This is easy but verbose to do with a decorator, and I imagine a bunch
of issues about the 'old' object with multiple decorators, so I omit it
here.  You might want a variety of such decorators.  Ie, using
copy.copy vs copy.deepcopy vs a special-case copy for a particular
class because there are large objects that are actually constant that
you don't want to copy (an "is" test would be enough, so the copy
would actually implement part of the contract).  Or the copy function
could be an argument to the decorator or a method on the object.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to