Skip to content

bpo-45566: test_frozen_pickle checks all pickle protocols #29150

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

Merged
merged 2 commits into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Lib/test/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2859,13 +2859,26 @@ class FrozenSlotsClass:
foo: str
bar: int

@dataclass(frozen=True)
class FrozenWithoutSlotsClass:
foo: str
bar: int

def test_frozen_pickle(self):
# bpo-43999

assert self.FrozenSlotsClass.__slots__ == ("foo", "bar")
p = pickle.dumps(self.FrozenSlotsClass("a", 1))
assert pickle.loads(p) == self.FrozenSlotsClass("a", 1)

self.assertEqual(self.FrozenSlotsClass.__slots__, ("foo", "bar"))
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(proto=proto):
obj = self.FrozenSlotsClass("a", 1)
p = pickle.loads(pickle.dumps(obj, protocol=proto))
self.assertIsNot(obj, p)
self.assertEqual(obj, p)

obj = self.FrozenWithoutSlotsClass("a", 1)
p = pickle.loads(pickle.dumps(obj, protocol=proto))
self.assertIsNot(obj, p)
self.assertEqual(obj, p)

class TestDescriptors(unittest.TestCase):
def test_set_name(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``test_frozen_pickle`` in ``test_dataclasses`` to check all ``pickle`` versions.