mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
Introducing __reduce_ex__, which is called with a protocol number argument
if it exists in preference over __reduce__. Now Tim can go implement this in cPickle.c.
This commit is contained in:
parent
2b0643a95d
commit
c53f009f94
4 changed files with 36 additions and 19 deletions
|
@ -109,6 +109,17 @@ def _better_reduce(obj):
|
|||
dictitems = obj.iteritems()
|
||||
return __newobj__, (cls,) + args, state, listitems, dictitems
|
||||
|
||||
# Extended reduce:
|
||||
|
||||
def _reduce_ex(obj, proto=0):
|
||||
obj_reduce = getattr(obj, "__reduce__", None)
|
||||
if obj_reduce and obj.__class__.__reduce__ is not object.__reduce__:
|
||||
return obj_reduce()
|
||||
elif proto < 2:
|
||||
return _reduce(obj)
|
||||
else:
|
||||
return _better_reduce(obj)
|
||||
|
||||
def _slotnames(cls):
|
||||
"""Return a list of slot names for a given class.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue