mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
This commit is contained in:
parent
a43fd0c899
commit
e690883ccf
3 changed files with 65 additions and 32 deletions
|
@ -113,9 +113,14 @@ def _better_reduce(obj):
|
|||
|
||||
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:
|
||||
# XXX This fails in test_copy.py line 61
|
||||
if obj_reduce:
|
||||
try:
|
||||
if obj.__class__.__reduce__ is not object.__reduce__:
|
||||
return obj_reduce()
|
||||
except AttributeError:
|
||||
pass
|
||||
if proto < 2:
|
||||
return _reduce(obj)
|
||||
else:
|
||||
return _better_reduce(obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue