Skip to content

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

Open
vstinner wants to merge 6 commits intopython:mainfrom
vstinner:frozendict_pickle2
Open

gh-141510, PEP 814: Add frozendict support to pickle#144967
vstinner wants to merge 6 commits intopython:mainfrom
vstinner:frozendict_pickle2

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Feb 18, 2026

Add frozendict.__getnewargs__() method.

Add frozendict.__getnewargs__() method.
Copy link
Member

Choose a reason for hiding this comment

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

Would not be better to add this test in test_frozendict.py? Together with tests for copy() and deepcopy()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I moved this test to test_pickle.

Copy link
Member Author

Choose a reason for hiding this comment

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

Together with tests for copy() and deepcopy()?

Commit dd64e42, which adds frozendict support to the copy module, added frozendict tests to test_copy.

@vstinner
Copy link
Member Author

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

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

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
Member

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

def test_recursive_dict_and_inst(self):
self._test_recursive_collection_and_inst(dict.fromkeys, oldminproto=0)

def test_recursive_frozendict_and_inst(self):
Copy link
Member

Choose a reason for hiding this comment

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

Please add tests for frozendict subclass, like test_recursive_frozenset_subclass_and_inst.

Please add tests for different types of recursion:

  • frozendict -> mutable value (list) -> frozendict
  • frozendict -> mutable key -> frozendict

All tests should be repeated for a frozendict subclass.

@vstinner
Copy link
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.

p = pickle.dumps(fd, proto)
fd2 = pickle.loads(p)
self.assertEqual(fd2, fd)
self.assertEqual(type(fd2), type(fd))
Copy link
Member

Choose a reason for hiding this comment

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

For FrozenDictSlots, test also the slot value (non-default). And maybe the value of a non-slot attribute, For FrozenDict, also test an attribute value.

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

Comments