summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_genericalias.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_genericalias.py')
-rw-r--r--Lib/test/test_genericalias.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index fd024dc..9f92739 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -353,6 +353,12 @@ class BaseTest(unittest.TestCase):
self.assertEqual(repr(C4[dict]).split(".")[-1], "Callable[[int, dict], str]")
self.assertEqual(C4[dict], Callable[[int, dict], str])
+ # substitute a nested GenericAlias (both typing and the builtin
+ # version)
+ C5 = Callable[[typing.List[T], tuple[K, T], V], int]
+ self.assertEqual(C5[int, str, float],
+ Callable[[typing.List[int], tuple[str, int], float], int])
+
with self.subTest("Testing type erasure"):
class C1(Callable):
def __call__(self):
@@ -391,5 +397,16 @@ class BaseTest(unittest.TestCase):
self.assertEqual(repr(C1), "collections.abc.Callable"
"[typing.Concatenate[int, ~P], int]")
+ with self.subTest("Testing TypeErrors"):
+ with self.assertRaisesRegex(TypeError, "variables left in"):
+ alias[int]
+ P = typing.ParamSpec('P')
+ C1 = Callable[P, T]
+ with self.assertRaisesRegex(TypeError, "many arguments for"):
+ C1[int, str, str]
+ with self.assertRaisesRegex(TypeError, "few arguments for"):
+ C1[int]
+
+
if __name__ == "__main__":
unittest.main()