bpo-46386: improve test_typing:test_immutability_by_copy_and_pickle
(GH-30613)
This commit is contained in:
parent
acf7403f9b
commit
09087b8519
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user