bpo-41064: Improve syntax error for invalid usage of '**' in f-strings (GH-25006)

This commit is contained in:
Pablo Galindo 2021-03-24 19:34:17 +00:00 committed by GitHub
parent 4958f5d69d
commit 8efad61963
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 1 deletions

View file

@ -1275,5 +1275,14 @@ x = (
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()