https://github.com/python/cpython/commit/84af8f5c5a5f7aee763eb175557765b18a5fd9e5
commit: 84af8f5c5a5f7aee763eb175557765b18a5fd9e5
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-07-06T14:20:55Z
summary:

[3.15] Add tests for syntax error messages that had no test coverage 
(GH-153192) (GH-153196)

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 <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>

files:
M Lib/test/test_fstring.py
M Lib/test/test_syntax.py
M Lib/test/test_unpack_ex.py

diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 5cc02c30ec2ba3..9a8e56836fc671 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -1706,6 +1706,9 @@ def test_invalid_syntax_error_message(self):
         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 ','.")
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 232dcb92ed2901..7859387dccef37 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -2238,6 +2238,16 @@
 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
diff --git a/Lib/test/test_unpack_ex.py b/Lib/test/test_unpack_ex.py
index 33c96b84964b59..4fe19765cacf11 100644
--- a/Lib/test/test_unpack_ex.py
+++ b/Lib/test/test_unpack_ex.py
@@ -355,6 +355,20 @@
         ^^^
     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
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to