8000 gh-105433: Add `pickle` tests for PEP695 by sobolevn · Pull Request #105443 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105433: Add pickle tests for PEP695 #105443

8000
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 3 commits into from
Jun 16, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Also test instances
  • Loading branch information
sobolevn committed Jun 7, 2023
commit 045339163083002ec59f26150fc47b103bdd4aab
20 changes: 19 additions & 1 deletion Lib/test/test_type_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,13 +867,21 @@ class Class4[X: int, Y: (bytes, str)]: ...


class TypeParamsPickleTest(unittest.TestCase):
def test_pickling(self):
def test_pickling_functions(self):
things_to_test = [
func1,
func2,
func3,
func4,
]
for thing in things_to_test:
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(thing=thing, proto=proto):
pickled = pickle.dumps(thing, protocol=proto)
self.assertEqual(pickle.loads(pickled), thing)

def test_pickling_classes(self):
things_to_test = [
Class1,
Class1[int],
Class1[T],
Expand All @@ -897,3 +905,13 @@ def test_pickling(self):
with self.subTest(thing=thing, proto=proto):
pickled = pickle.dumps(thing, protocol=proto)
self.assertEqual(pickle.loads(pickled), thing)

for klass in things_to_test:
real_class = getattr(klass, '__origin__', klass)
thing = klass()
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(thing=thing, proto=proto):
pickled = pickle.dumps(thing, protocol=proto)
# These instances are not equal,
# but class check is good enough:
self.assertIsInstance(pickle.loads(pickled), real_class)
0