bpo-41064: Improve syntax error for invalid usage of '**' in f-strings (GH-25006)
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index d7143d1..79e123f 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -1275,5 +1275,14 @@ def test_with_an_underscore_and_a_comma_in_format_specifier(self):
with self.assertRaisesRegex(ValueError, error_msg):
f'{1:_,}'
+ def test_syntax_error_for_starred_expressions(self):
+ error_msg = re.escape("can't use starred expression here")
+ with self.assertRaisesRegex(SyntaxError, error_msg):
+ compile("f'{*a}'", "?", "exec")
+
+ error_msg = re.escape("can't use double starred expression here")
+ with self.assertRaisesRegex(SyntaxError, error_msg):
+ compile("f'{**a}'", "?", "exec")
+
if __name__ == '__main__':
unittest.main()