mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Changes to copy() and deepcopy() in copy.py to support __reduce__ as a
fallback for objects that are neither supported by our dispatch table nor have a __copy__ or __deepcopy__ method. Changes to _reduce() in copy_reg.py to support reducing objects that don't have a __dict__ -- copy.copy(complex()) now invokes _reduce(). Add tests for copy.copy() and copy.deepcopy() to test_regrtest.py.
This commit is contained in:
parent
19405a4a2a
commit
6cef6d5d62
3 changed files with 91 additions and 9 deletions
|
@ -54,4 +54,12 @@ def _reduce(self):
|
|||
state = None
|
||||
else:
|
||||
state = base(self)
|
||||
return _reconstructor, (self.__class__, base, state), self.__dict__
|
||||
args = (self.__class__, base, state)
|
||||
try:
|
||||
dict = self.__dict__
|
||||
except AttributeError:
|
||||
dict = None
|
||||
if dict:
|
||||
return _reconstructor, args, dict
|
||||
else:
|
||||
return _reconstructor, args
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue