]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add tests for syntax error messages that had no test coverage (GH-153192)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 6 Jul 2026 13:49:17 +0000 (16:49 +0300)
committerGitHub <noreply@github.com>
Mon, 6 Jul 2026 13:49:17 +0000 (16:49 +0300)
"illegal target for annotation" and "cannot use dict unpacking here"
were not tested at all, and "f-string: expecting '!', or ':', or '}'"
was only tested for its t-string variant.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Lib/test/test_fstring.py
Lib/test/test_syntax.py
Lib/test/test_unpack_ex.py

index 5cc02c30ec2ba3391e313087e29859dec7936929..9a8e56836fc671c06ae41297ebb56757551981dc 100644 (file)
@@ -1706,6 +1706,9 @@ except Exception:
         with self.assertRaisesRegex(SyntaxError,
                                     "f-string: expecting '=', or '!', or ':', or '}'"):
             compile("f'{a $ b}'", "?", "exec")
+        with self.assertRaisesRegex(SyntaxError,
+                                    "f-string: expecting '!', or ':', or '}'"):
+            compile("f'{a=b}'", "?", "exec")
 
     def test_with_two_commas_in_format_specifier(self):
         error_msg = re.escape("Cannot specify ',' with ','.")
index 29278d928fbb402df19a3fa6659666a3b056858e..a63042055210c5c8f2e2a3250c72b3090a415c79 100644 (file)
@@ -2238,6 +2238,16 @@ SyntaxError: only single target (not tuple) can be annotated
 Traceback (most recent call last):
 SyntaxError: only single target (not list) can be annotated
 
+>>> 1: int
+Traceback (most recent call last):
+SyntaxError: illegal target for annotation
+>>> -x: int = 1
+Traceback (most recent call last):
+SyntaxError: illegal target for annotation
+>>> (x for x in y): int
+Traceback (most recent call last):
+SyntaxError: illegal target for annotation
+
 # 'not' after operators:
 
 >>> 3 + not 3
index 33c96b84964b591ced7b1d0d8a89dc7a8f136ac9..4fe19765cacf1108f8cd01c87aca58e4b2787546 100644 (file)
@@ -355,6 +355,20 @@ Error messages for specific failure modes of unpacking
         ^^^
     SyntaxError: cannot use dict unpacking in a dictionary value
 
+    >>> (**a)
+    Traceback (most recent call last):
+    ...
+    (**a)
+     ^^
+    SyntaxError: cannot use dict unpacking here
+
+    >>> {**a for a in {1: 2}.items(): b}
+    Traceback (most recent call last):
+    ...
+    {**a for a in {1: 2}.items(): b}
+     ^^
+    SyntaxError: cannot use dict unpacking here
+
 
 # Generator expression in function arguments