gh-93627: Align copy module behaviour with pickle module by eendebakpt · Pull Request #109498 · python/cpython
In this PR we align the behavior of the copy module with the pickle module. See #93627 and #103035 for more discussion. For example:
import copy
class C(object):
__copy__ = None
x= C()
copy.copy(x) # returns a copy on main, with this PR raises a TypeError
The more consistent behaviour in this PR has to be weighted against the alternative option: keep the current behaviour (which is backwards compatible).
Some notes:
-
Changing the behaviour does not break any existing unit tests. For either this PR, or the keeping the current behaviour, we can add tests to ensure the behaviour in the future.
-
One variation is to change the behavior of
__reduce_ex__and__reduce__attributes to align withpickle, but do not modify the behaviour of__copy__and__deepcopy__(these methods are specific for the copy module and not present in the pickle module