[issue20679] 3.4 cherry-pick: 587fd4b91120 improve Enum subclass behavior

Ethan Furman report at bugs.python.org
Fri Feb 21 03:34:52 CET 2014


Ethan Furman added the comment:

When I implemented pickle support I did not have a complete understanding of the pickle protocols nor how to best use them.  As a result, I picked __getnewargs__ and only supported protocols 2 and 3 (4 didn't exist yet).

Serhiy came along and explained a bunch of it to me, so now I know that __reduce_ex__ is the best choice as it supports all the protocol levels, and is always used [1].  The patch removes __getnewargs__ and makes __reduce_ex__ The One Obvious Way, but if it does not go in to 3.4.0 then I won't be able to remove __getnewargs__ because of backwards compatibility.

All the tests still pass, and the new test for subclassing to pickle by name passes.


[1] pickle supports two low-level methods: __reduce__ and __reduce_ex__; __reduce_ex__ is more powerful and is the preferred method.  If a mix-in class to Enum defines __reduce_ex__ and Enum only defines __reduce__, Enum's __reduce__ will not be called.

----------

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


More information about the Python-bugs-list mailing list