summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_genericalias.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-09-15 18:25:41 (GMT)
committerGitHub <noreply@github.com>2021-09-15 18:25:41 (GMT)
commit5dce51a8875d9639786741e962b3cb208596b096 (patch)
treedc3f0242389915b40d32eb4c196f3c8f2ea24766 /Lib/test/test_genericalias.py
parent84a6061e29e9dc13909bdf6f541f48c2a4f1d410 (diff)
downloadcpython-5dce51a8875d9639786741e962b3cb208596b096.zip
cpython-5dce51a8875d9639786741e962b3cb208596b096.tar.gz
cpython-5dce51a8875d9639786741e962b3cb208596b096.tar.bz2
bpo-45167: Fix deepcopying of GenericAlias (GH-28324)
Diffstat (limited to 'Lib/test/test_genericalias.py')
-rw-r--r--Lib/test/test_genericalias.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index 2e70e75..0daaff0 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -2,6 +2,7 @@
import unittest
import pickle
+import copy
from collections import (
defaultdict, deque, OrderedDict, Counter, UserDict, UserList
)
@@ -270,11 +271,30 @@ class BaseTest(unittest.TestCase):
def test_pickle(self):
alias = GenericAlias(list, T)
- s = pickle.dumps(alias)
- loaded = pickle.loads(s)
- self.assertEqual(alias.__origin__, loaded.__origin__)
- self.assertEqual(alias.__args__, loaded.__args__)
- self.assertEqual(alias.__parameters__, loaded.__parameters__)
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ s = pickle.dumps(alias, proto)
+ loaded = pickle.loads(s)
+ self.assertEqual(loaded.__origin__, alias.__origin__)
+ self.assertEqual(loaded.__args__, alias.__args__)
+ self.assertEqual(loaded.__parameters__, alias.__parameters__)
+
+ def test_copy(self):
+ class X(list):
+ def __copy__(self):
+ return self
+ def __deepcopy__(self, memo):
+ return self
+
+ for origin in list, deque, X:
+ alias = GenericAlias(origin, T)
+ copied = copy.copy(alias)
+ self.assertEqual(copied.__origin__, alias.__origin__)
+ self.assertEqual(copied.__args__, alias.__args__)
+ self.assertEqual(copied.__parameters__, alias.__parameters__)
+ copied = copy.deepcopy(alias)
+ self.assertEqual(copied.__origin__, alias.__origin__)
+ self.assertEqual(copied.__args__, alias.__args__)
+ self.assertEqual(copied.__parameters__, alias.__parameters__)
def test_union(self):
a = typing.Union[list[int], list[str]]