diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2022-01-16 07:32:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-16 07:32:11 (GMT) |
commit | 09087b8519316608b85131ee7455b664c00c38d2 (patch) | |
tree | ec1a9f5d510e860942f43b21af1d9dafa1487064 /Lib/test | |
parent | acf7403f9baea3ae1119fc6b4a3298522188bf96 (diff) | |
download | cpython-09087b8519316608b85131ee7455b664c00c38d2.zip cpython-09087b8519316608b85131ee7455b664c00c38d2.tar.gz cpython-09087b8519316608b85131ee7455b664c00c38d2.tar.bz2 |
bpo-46386: improve `test_typing:test_immutability_by_copy_and_pickle` (GH-30613)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_typing.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index cf719df..c8a077e 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -2130,22 +2130,30 @@ class GenericTests(BaseTestCase): def test_immutability_by_copy_and_pickle(self): # Special forms like Union, Any, etc., generic aliases to containers like List, # Mapping, etc., and type variabcles are considered immutable by copy and pickle. - global TP, TPB, TPV # for pickle + global TP, TPB, TPV, PP # for pickle TP = TypeVar('TP') TPB = TypeVar('TPB', bound=int) TPV = TypeVar('TPV', bytes, str) - for X in [TP, TPB, TPV, List, typing.Mapping, ClassVar, typing.Iterable, + PP = ParamSpec('PP') + for X in [TP, TPB, TPV, PP, + List, typing.Mapping, ClassVar, typing.Iterable, Union, Any, Tuple, Callable]: - self.assertIs(copy(X), X) - self.assertIs(deepcopy(X), X) - self.assertIs(pickle.loads(pickle.dumps(X)), X) + with self.subTest(thing=X): + self.assertIs(copy(X), X) + self.assertIs(deepcopy(X), X) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + self.assertIs(pickle.loads(pickle.dumps(X, proto)), X) + del TP, TPB, TPV, PP + # Check that local type variables are copyable. TL = TypeVar('TL') TLB = TypeVar('TLB', bound=int) TLV = TypeVar('TLV', bytes, str) - for X in [TL, TLB, TLV]: - self.assertIs(copy(X), X) - self.assertIs(deepcopy(X), X) + PL = ParamSpec('PL') + for X in [TL, TLB, TLV, PL]: + with self.subTest(thing=X): + self.assertIs(copy(X), X) + self.assertIs(deepcopy(X), X) def test_copy_generic_instances(self): T = TypeVar('T') |