diff options
author | Guido van Rossum <guido@python.org> | 2016-10-29 19:44:29 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2016-10-29 19:44:29 (GMT) |
commit | b7dedc89f1ec476352f3678d0c55252159da27df (patch) | |
tree | ceabb55abc070241c5e01ca163288deb52751e4d /Lib/test/test_typing.py | |
parent | 5fc25a873cfdec27e46f71e62c9b65df5667c1b4 (diff) | |
download | cpython-b7dedc89f1ec476352f3678d0c55252159da27df.zip cpython-b7dedc89f1ec476352f3678d0c55252159da27df.tar.gz cpython-b7dedc89f1ec476352f3678d0c55252159da27df.tar.bz2 |
Issue #28556: updates to typing.py (fix copy, deepcopy, pickle)
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r-- | Lib/test/test_typing.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 8e0a8c5..b50f366 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -4,6 +4,7 @@ import pickle import re import sys from unittest import TestCase, main, skipUnless, SkipTest +from copy import copy, deepcopy from typing import Any from typing import TypeVar, AnyStr @@ -845,6 +846,24 @@ class GenericTests(BaseTestCase): self.assertEqual(x.foo, 42) self.assertEqual(x.bar, 'abc') self.assertEqual(x.__dict__, {'foo': 42, 'bar': 'abc'}) + simples = [Any, Union, Tuple, Callable, ClassVar, List, typing.Iterable] + for s in simples: + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + z = pickle.dumps(s, proto) + x = pickle.loads(z) + self.assertEqual(s, x) + + def test_copy_and_deepcopy(self): + T = TypeVar('T') + class Node(Generic[T]): ... + things = [Union[T, int], Tuple[T, int], Callable[..., T], Callable[[int], int], + Tuple[Any, Any], Node[T], Node[int], Node[Any], typing.Iterable[T], + typing.Iterable[Any], typing.Iterable[int], typing.Dict[int, str], + typing.Dict[T, Any], ClassVar[int], ClassVar[List[T]], Tuple['T', 'T'], + Union['T', int], List['T'], typing.Mapping['T', int]] + for t in things + [Any]: + self.assertEqual(t, copy(t)) + self.assertEqual(t, deepcopy(t)) def test_errors(self): with self.assertRaises(TypeError): |