|
4 | 4 | import re
|
5 | 5 | import sys
|
6 | 6 | from unittest import TestCase, main, skipUnless, SkipTest
|
| 7 | +from copy import copy, deepcopy |
7 | 8 |
|
8 | 9 | from typing import Any
|
9 | 10 | from typing import TypeVar, AnyStr
|
@@ -845,6 +846,24 @@ class C(B[int]):
|
845 | 846 | self.assertEqual(x.foo, 42)
|
846 | 847 | self.assertEqual(x.bar, 'abc')
|
847 | 848 | self.assertEqual(x.__dict__, {'foo': 42, 'bar': 'abc'})
|
| 849 | + simples = [Any, Union, Tuple, Callable, ClassVar, List, typing.Iterable] |
| 850 | + for s in simples: |
| 851 | + for proto in range(pickle.HIGHEST_PROTOCOL + 1): |
| 852 | + z = pickle.dumps(s, proto) |
| 853 | + x = pickle.loads(z) |
| 854 | + self.assertEqual(s, x) |
| 855 | + |
| 856 | + def test_copy_and_deepcopy(self): |
| 857 | + T = TypeVar('T') |
| 858 | + class Node(Generic[T]): ... |
| 859 | + things = [Union[T, int], Tuple[T, int], Callable[..., T], Callable[[int], int], |
| 860 | + Tuple[Any, Any], Node[T], Node[int], Node[Any], typing.Iterable[T], |
| 861 | + typing.Iterable[Any], typing.Iterable[int], typing.Dict[int, str], |
| 862 | + typing.Dict[T, Any], ClassVar[int], ClassVar[List[T]], Tuple['T', 'T'], |
| 863 | + Union['T', int], List['T'], typing.Mapping['T', int]] |
| 864 | + for t in things + [Any]: |
| 865 | + self.assertEqual(t, copy(t)) |
| 866 | + self.assertEqual(t, deepcopy(t)) |
848 | 867 |
|
849 | 868 | def test_errors(self):
|
850 | 869 | with self.assertRaises(TypeError):
|
|
0 commit comments