[issue6827] deepcopy erroneously doesn't call __setstate__ if __getstate__ returns empty dict

R. David Murray report at bugs.python.org
Thu Feb 4 17:21:42 CET 2010


R. David Murray <rdmurray at bitdance.com> added the comment:

The documentation also says, "if the object defines both a __getstate__ and a __setstate__ method, the state object does not need to be a dictionary and the methods can do what they want."  In issue 7848 (which I will close as a duplicate of this issue), the object wants to return a single integer as the state, and that integer can happen to be zero, so clearly "anything they want" is demonstrably not true.  Granted that this can also be worked around with a __new__ method, it feels like a broken API.  It unnecessarily complicates the implementation of objects that implement the protocol but whose state object can legitimately taken on a False value.  It also breaks the principle of least surprise for someone taking advantage of the "anything they want" clause (it may not occur to them that the 'black blox' state they are passing between their methods could take on a False value...and therefore break their code).

Since this was clearly a conscious choice for new-style classes, does anyone know why it was made?

----------
keywords: +easy
nosy: +r.david.murray
priority:  -> normal
status: pending -> open
versions: +Python 2.6, Python 2.7, Python 3.1, Python 3.2 -Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6827>
_______________________________________


More information about the Python-bugs-list mailing list