File size: 2,336 Bytes
5a9e79d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
diff --git a/Lib/test/test_pep646_aug.py b/Lib/test/test_pep646_aug.py
new file mode 100644
index 0000000000..0abcc8fce9
--- /dev/null
+++ b/Lib/test/test_pep646_aug.py
@@ -0,0 +1,73 @@
+import io
+import unittest
+
+from test import test_pep646_syntax
+
+
+class VariadicGenericsAugmentedTest(unittest.TestCase):
+
+    def test_pep646_syntax_doctest_examples(self):
+        test_pep646_syntax.test_main(verbose=False)
+
+    def test_starred_vararg_annotation_runtime_value(self):
+        ns = {}
+        exec(
+            "from typing import TypeVarTuple\n"
+            "Ts = TypeVarTuple('Ts')\n"
+            "def f(*args: *Ts):\n"
+            "    pass\n",
+            ns,
+        )
+
+        annotation = ns["f"].__annotations__["args"]
+        self.assertNotIsInstance(annotation, tuple)
+        self.assertEqual(repr(annotation), "*Ts")
+
+    def test_future_starred_vararg_annotation_string(self):
+        ns = {}
+        exec(
+            "from __future__ import annotations\n"
+            "from typing import TypeVarTuple\n"
+            "Ts = TypeVarTuple('Ts')\n"
+            "def f(*args: *Ts):\n"
+            "    pass\n",
+            ns,
+        )
+
+        self.assertEqual(ns["f"].__annotations__["args"], "*Ts")
+
+    def test_plain_vararg_annotation_still_uses_value(self):
+        ns = {}
+        exec(
+            "def f(*args: int):\n"
+            "    pass\n",
+            ns,
+        )
+
+        self.assertIs(ns["f"].__annotations__["args"], int)
+
+    def test_existing_grammar_suite_still_passes(self):
+        stream = io.StringIO()
+        suite = unittest.defaultTestLoader.loadTestsFromName("test.test_grammar")
+        result = unittest.TextTestRunner(
+            stream=stream,
+            verbosity=0,
+            buffer=False,
+        ).run(suite)
+
+        self.assertTrue(result.wasSuccessful(), stream.getvalue())
+
+    def test_existing_compile_suite_still_passes(self):
+        stream = io.StringIO()
+        suite = unittest.defaultTestLoader.loadTestsFromName("test.test_compile")
+        result = unittest.TextTestRunner(
+            stream=stream,
+            verbosity=0,
+            buffer=False,
+        ).run(suite)
+
+        self.assertTrue(result.wasSuccessful(), stream.getvalue())
+
+
+if __name__ == "__main__":
+    unittest.main()