]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-108983: Add more PEP 526 tests to `test_grammar` (#108984)
authorNikita Sobolev <mail@sobolevn.me>
Wed, 6 Sep 2023 13:41:38 +0000 (16:41 +0300)
committerGitHub <noreply@github.com>
Wed, 6 Sep 2023 13:41:38 +0000 (06:41 -0700)
Lib/test/test_grammar.py

index 8507a07e498532c4cfad1629c021437649870080..7c15a23a69163bed302fe6a8252998f0073b3259 100644 (file)
@@ -350,6 +350,11 @@ class GrammarTests(unittest.TestCase):
         check_syntax_error(self, "x: int: str")
         check_syntax_error(self, "def f():\n"
                                  "    nonlocal x: int\n")
+        check_syntax_error(self, "def f():\n"
+                                 "    global x: int\n")
+        check_syntax_error(self, "x: int = y = 1")
+        check_syntax_error(self, "z = w: int = 1")
+        check_syntax_error(self, "x: int = y: int = 1")
         # AST pass
         check_syntax_error(self, "[x, 0]: int\n")
         check_syntax_error(self, "f(): int\n")
@@ -363,6 +368,12 @@ class GrammarTests(unittest.TestCase):
         check_syntax_error(self, "def f():\n"
                                  "    global x\n"
                                  "    x: int\n")
+        check_syntax_error(self, "def f():\n"
+                                 "    x: int\n"
+                                 "    nonlocal x\n")
+        check_syntax_error(self, "def f():\n"
+                                 "    nonlocal x\n"
+                                 "    x: int\n")
 
     def test_var_annot_basic_semantics(self):
         # execution order