Skip to content

Commit

Permalink
gh-109114: Relax the check for invalid lambdas inside f-strings to av…
Browse files Browse the repository at this point in the history
…oid false positives
  • Loading branch information
pablogsal committed Sep 8, 2023
1 parent b9831e5 commit fee6000
Show file tree
Hide file tree
Showing 3 changed files with 1,253 additions and 1,309 deletions.
2 changes: 1 addition & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ invalid_expression:
_PyPegen_check_legacy_stmt(p, a) ? NULL : p->tokens[p->mark-1]->level == 0 ? NULL :
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") }
| a=disjunction 'if' b=disjunction !('else'|':') { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected 'else' after 'if' expression") }
| a='lambda' [lambda_params] b=':' &(FSTRING_MIDDLE | fstring_replacement_field) {
| a='lambda' [lambda_params] b=':' &FSTRING_MIDDLE {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "f-string: lambda expressions are not allowed without parentheses") }

invalid_named_expression(memo):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Relax the detection of the error message for invalid lambdas inside
f-strings to not search for arbitrary replacement fields to avoid false
positives. Patch by Pablo Galindo

0 comments on commit fee6000

Please sign in to comment.