]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] Add tests for syntax error messages that had no test coverage (GH-153192)...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 6 Jul 2026 14:20:55 +0000 (16:20 +0200)
committerGitHub <noreply@github.com>
Mon, 6 Jul 2026 14:20:55 +0000 (14:20 +0000)
Add tests for syntax error messages that had no test coverage (GH-153192)

"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.
(cherry picked from commit 836b2069c86e25cf9456e9210bb612e5166d0779)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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 232dcb92ed2901f5bc0f5b7123f11162ac964aa4..7859387dccef3768f8df5d13d49f5c10dcf84d27 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