◐ Shell
reader mode source ↗
Skip to content

gh-141510, PEP 814: Add frozendict support to pickle#144967

Merged
vstinner merged 10 commits into
python:mainfrom
vstinner:frozendict_pickle2
Feb 21, 2026
Merged

gh-141510, PEP 814: Add frozendict support to pickle#144967
vstinner merged 10 commits into
python:mainfrom
vstinner:frozendict_pickle2

Conversation

@vstinner

@vstinner vstinner commented Feb 18, 2026

Copy link
Copy Markdown
Member

Add frozendict.__getnewargs__() method.

Add frozendict.__getnewargs__() method.
@vstinner

Copy link
Copy Markdown
Member Author

@serhiy-storchaka: I addressed your review. Please review the updated PR.

@serhiy-storchaka serhiy-storchaka 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.

Hide comment

What about frozendict views and iterators? Are they copyable/pickleable?

Are there tests for deepcopying?

I am surprised that there is no separate test_frozendict.py.

@serhiy-storchaka

Copy link
Copy Markdown
Member

Oh, I don't think deepcopy of frozendict is correct. It does not work for recursive frozendict.

@vstinner

Copy link
Copy Markdown
Member Author

I will try to update my PR later to address other comments.

What about frozendict views and iterators? Are they copyable/pickleable?

keys, values and items views cannot be copied nor serialized by pickle.

Ah, it seems like it's possible to serialize a frozendict iterator.

Are there tests for deepcopying?

test_copy.test_deepcopy_frozendict() tests frozendict deepcopy.

I am surprised that there is no separate test_frozendict.py.

Ah. It was simple to add frozendict tests to existing test_dict. Maybe we can create test_frozendict later once we will add more tests.

@vstinner

Copy link
Copy Markdown
Member Author

Oh, I don't think deepcopy of frozendict is correct. It does not work for recursive frozendict.

You're right, the current copy.deepcopy() implementation doesn't work for recursive frozendict.

@vstinner

Copy link
Copy Markdown
Member Author

I completed the PR to add requested tests.

@vstinner

Copy link
Copy Markdown
Member Author

You're right, the current copy.deepcopy() implementation doesn't work for recursive frozendict.

I created #145027 to fix copy.deepcopy() for recursive frozendict.

@vstinner

Copy link
Copy Markdown
Member Author

If things are pickleable, they should also be deepcopyable. It is worth to have explicit deepcopy tests, because they can preserve additional invariants. For example, it should be possible to deepcopy a frozendict containing lambdas or modules.

I propose merging this PR first (once it will be approved), and then adding such tests to #145027 PR.

@serhiy-storchaka

Copy link
Copy Markdown
Member

Did you forget to push changes for comments which you marked resolved?

@vstinner

Copy link
Copy Markdown
Member Author

Ooops, you're correct. I forgot to push my changes, but I also removed my local branch... I had to rewrite my changes. I just pushed them. I should be ok now.

@serhiy-storchaka serhiy-storchaka 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.

Hide comment

LGTM. 👍

Hide details View details @vstinner vstinner merged commit 20b1535 into python:main Feb 21, 2026
49 checks passed
@vstinner vstinner deleted the frozendict_pickle2 branch February 21, 2026 10:07
@vstinner

Copy link
Copy Markdown
Member Author

Merged. Thanks for your great review @serhiy-storchaka, it was very useful!

@StanFromIreland

Copy link
Copy Markdown
Member

This broke Oddballs (i.e. text_xpickle): https://buildbot.python.org/#/builders/1868/builds/5

@vstinner

Copy link
Copy Markdown
Member Author

This broke Oddballs (i.e. text_xpickle): https://buildbot.python.org/#/builders/1868/builds/5

Oh, I'm not used to test_xpickle yet, I forgot about it. I wrote #145069 to fix test_xpickle.

brijkapadia pushed a commit to brijkapadia/cpython that referenced this pull request Feb 28, 2026
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.

3 participants