Skip to content

Commit c9de3e8

Browse files
committed
Catch more errors inside fstring_replacement_field
1 parent 0931f2e commit c9de3e8

File tree

2 files changed

+442
-470
lines changed

2 files changed

+442
-470
lines changed

Grammar/python.gram

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,10 +1358,7 @@ invalid_kvpair:
13581358
invalid_starred_expression:
13591359
| a='*' expression '=' b=expression { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to iterable argument unpacking") }
13601360
invalid_replacement_field:
1361-
| '{' a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: expression required before '='") }
1362-
| '{' a=':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: expression required before ':'") }
1363-
| '{' a='!' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: expression required before '!'") }
1364-
| '{' a='}' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: empty expression not allowed") }
1361+
| '{' !(yield_expr | star_expressions) { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting expression after '{'")}
13651362
| '{' (yield_expr | star_expressions) !('=' | '!' | ':' | '}') {
13661363
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting '=', or '!', or ':', or '}'") }
13671364
| '{' (yield_expr | star_expressions) '=' !('!' | ':' | '}') {

0 commit comments

Comments
 (0)