]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-108983: Add more PEP 526 tests to `test_grammar` (GH-108984) (#109000)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 8 Sep 2023 13:16:02 +0000 (06:16 -0700)
committerGitHub <noreply@github.com>
Fri, 8 Sep 2023 13:16:02 +0000 (15:16 +0200)
gh-108983: Add more PEP 526 tests to `test_grammar` (GH-108984)
(cherry picked from commit 1fb20d42c58924e2e941622b3539645c7b843e0e)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/test_grammar.py

index ee105a3de17f8a2f74aedd36a1e5228a4e954394..b2415d579145f55d67e5bf8a6ee3a3e79671f27c 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