Skip to content

gh-93627: Align copy module behaviour with pickle module #109498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Sep 16, 2023

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 with pickle, 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

@eendebakpt eendebakpt changed the title Draft: gh-93627: Align copy module behaviour with pickle module gh-93627: Align copy module behaviour with pickle module Sep 16, 2023
@eendebakpt
Copy link
Contributor Author

@serhiy-storchaka As the creator of the corresponding issue, would you be able to review this PR?

@skirpichev
Copy link
Member

I took liberty to fix a merge conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants