Skip to content

gh-141510: Implement copy and deepcopy for frozendict - #144905

Merged
vstinner merged 9 commits into
python:mainfrom
eendebakpt:copy_module_frozendict
Feb 18, 2026
Merged

vstinner merged 9 commits into
python:mainfrom
eendebakpt:copy_module_frozendict

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor
@eendebakpt eendebakpt changed the title gh-41510: Implement copy and deepcopy for frozendict Feb 17, 2026
@eendebakpt
eendebakpt marked this pull request as draft February 17, 2026 11:37

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it a draft PR?

Changes cherry-picked from #141508 by @vstinner

I'm surprised that you created a PR from my WIP work. I'm currently splitting this big PR into smaller pieces, as I wrote in the PR.

Comment thread Lib/test/test_copy.py Resolved
@eendebakpt

eendebakpt commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Draft because there are failing tests are due to making _deepcopy_dispatch immutable. The failing test is a bit strange, see

# This is an ugly hack:

I will look into this.

eendebakpt and others added 4 commits February 17, 2026 21:28
@eendebakpt

eendebakpt commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm surprised that you created a PR from my WIP work. I'm currently splitting this big PR into smaller pieces, as I wrote in the PR.

Sorry, my mistake. Feel free to close the PR if it is interfering.

Comment thread Lib/copy.py Outdated
return type(x)(x.__func__, deepcopy(x.__self__, memo))
d[types.MethodType] = _deepcopy_method

_deepcopy_dispatch = frozendict(d)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not convert it to a frozendict in this PR, since it's not directly related to supporting frozendict in copy: remove this line and revert test_descr changes.

@eendebakpt eendebakpt Feb 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it here. Do you want me to open a separate PR for this part?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote #144909 to use frozendict in multiple stdlib modules. I will to see how this PR goes before proposing changing copy._deepcopy_dispatch to frozendict.

Comment thread Lib/test/test_descr.py Resolved
@eendebakpt
eendebakpt marked this pull request as ready for review February 17, 2026 22:55
@vstinner
vstinner merged commit dd64e42 into python:main Feb 18, 2026
45 checks passed
@vstinner

Copy link
Copy Markdown
Member

Merged, thanks.

@vstinner

Copy link
Copy Markdown
Member

Ah, the implementation doesn't work for recursive frozendict. I created #145027 to fix copy.deepcopy() for recursive frozendict.

brijkapadia pushed a commit to brijkapadia/cpython that referenced this pull request Feb 28, 2026
…44905)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
…44905)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants