Message211739
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 [1] as it supports all the protocol levels, and is always used. 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 it because of backwards compatibility.
[1] Due to what I consider a bug in pickle (still need to create an issue for it, I think) if:
class BaseClass:
def __reduce_ex__(self, proto):
return some_tuple
class SubClass(BaseClass):
def __reduce__(self):
return a_different_tuple
huh = SubClass()
pickle.dumps(huh)
the dumps call will use BaseClass.__reduce_ex__ and not SubClass.__reduce__. For this reason Enum uses __reduce_ex__. |
|
Date |
User |
Action |
Args |
2014-02-21 02:25:12 | ethan.furman | unlink | issue20679 messages |
2014-02-20 18:05:26 | ethan.furman | set | recipients:
+ ethan.furman, barry, larry, eli.bendersky, serhiy.storchaka |
2014-02-20 18:05:26 | ethan.furman | set | messageid: <1392919526.76.0.518536733981.issue20679@psf.upfronthosting.co.za> |
2014-02-20 18:05:26 | ethan.furman | link | issue20679 messages |
2014-02-20 18:05:26 | ethan.furman | create | |
|