Skip to content

Commit 09087b8

Browse files
authored
bpo-46386: improve test_typing:test_immutability_by_copy_and_pickle (GH-30613)
1 parent acf7403 commit 09087b8

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Lib/test/test_typing.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,22 +2130,30 @@ class Node(Generic[T]): ...
21302130
def test_immutability_by_copy_and_pickle(self):
21312131
# Special forms like Union, Any, etc., generic aliases to containers like List,
21322132
# Mapping, etc., and type variabcles are considered immutable by copy and pickle.
2133-
global TP, TPB, TPV # for pickle
2133+
global TP, TPB, TPV, PP # for pickle
21342134
TP = TypeVar('TP')
21352135
TPB = TypeVar('TPB', bound=int)
21362136
TPV = TypeVar('TPV', bytes, str)
2137-
for X in [TP, TPB, TPV, List, typing.Mapping, ClassVar, typing.Iterable,
2137+
PP = ParamSpec('PP')
2138+
for X in [TP, TPB, TPV, PP,
2139+
List, typing.Mapping, ClassVar, typing.Iterable,
21382140
Union, Any, Tuple, Callable]:
2139-
self.assertIs(copy(X), X)
2140-
self.assertIs(deepcopy(X), X)
2141-
self.assertIs(pickle.loads(pickle.dumps(X)), X)
2141+
with self.subTest(thing=X):
2142+
self.assertIs(copy(X), X)
2143+
self.assertIs(deepcopy(X), X)
2144+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2145+
self.assertIs(pickle.loads(pickle.dumps(X, proto)), X)
2146+
del TP, TPB, TPV, PP
2147+
21422148
# Check that local type variables are copyable.
21432149
TL = TypeVar('TL')
21442150
TLB = TypeVar('TLB', bound=int)
21452151
TLV = TypeVar('TLV', bytes, str)
2146-
for X in [TL, TLB, TLV]:
2147-
self.assertIs(copy(X), X)
2148-
self.assertIs(deepcopy(X), X)
2152+
PL = ParamSpec('PL')
2153+
for X in [TL, TLB, TLV, PL]:
2154+
with self.subTest(thing=X):
2155+
self.assertIs(copy(X), X)
2156+
self.assertIs(deepcopy(X), X)
21492157

21502158
def test_copy_generic_instances(self):
21512159
T = TypeVar('T')

0 commit comments

Comments
 (0)