summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_genericalias.py
diff options
context:
space:
mode:
authorkj <28750310+Fidget-Spinner@users.noreply.github.com>2020-12-24 02:47:40 (GMT)
committerGitHub <noreply@github.com>2020-12-24 02:47:40 (GMT)
commit6dd3da3cf4a0d6cb62d9c2a155434c127183454d (patch)
tree772fbdf7ba137564d990fa96a323bc19c0249bd8 /Lib/test/test_genericalias.py
parenteee1c7745ab4eb4f75153e71aaa2a62018b7625a (diff)
downloadcpython-6dd3da3cf4a0d6cb62d9c2a155434c127183454d.zip
cpython-6dd3da3cf4a0d6cb62d9c2a155434c127183454d.tar.gz
cpython-6dd3da3cf4a0d6cb62d9c2a155434c127183454d.tar.bz2
bpo-42195: Override _CallableGenericAlias's __getitem__ (GH-23915)
Added `__getitem__` for `_CallableGenericAlias` so that it returns a subclass (itself) of `types.GenericAlias` rather than the default behavior of returning a plain `types.GenericAlias`. This fixes `repr` issues occuring after `TypeVar` substitution arising from the previous behavior.
Diffstat (limited to 'Lib/test/test_genericalias.py')
-rw-r--r--Lib/test/test_genericalias.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index 5de13fe..ccf40b1 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -347,6 +347,12 @@ class BaseTest(unittest.TestCase):
self.assertEqual(C2[int, float, str], Callable[[int, float], str])
self.assertEqual(C3[int], Callable[..., int])
+ # multi chaining
+ C4 = C2[int, V, str]
+ self.assertEqual(repr(C4).split(".")[-1], "Callable[[int, ~V], str]")
+ self.assertEqual(repr(C4[dict]).split(".")[-1], "Callable[[int, dict], str]")
+ self.assertEqual(C4[dict], Callable[[int, dict], str])
+
with self.subTest("Testing type erasure"):
class C1(Callable):
def __call__(self):