◐ Shell
clean mode source ↗

GH-103727: Avoid advancing tokenizer too far in f-string mode by lysnikolaou · Pull Request #103775 · python/cpython

@lysnikolaou

@pablogsal @isidentical @sunmy2019 I'm okay with lambdas containing syntax errors emitting this error message as well. Anyone have objections on that?

In case people find it better, we could change the error message to something like f-string: invalid syntax. If you meant to use a lambda, it needs to be parenthesized.

@pablogsal

@pablogsal @isidentical @sunmy2019 I'm okay with lambdas containing syntax errors emitting this error message as well. Anyone have objections on that?

In case people find it better, we could change the error message to something like f-string: invalid syntax. If you meant to use a lambda, it needs to be parenthesized.

I'm fine with this. Is unlikely that people try lambdas in fstrings so I am not worried about the error message

pablogsal

pablogsal

"f-string: expecting a valid expression after '{'",
["f'{lambda x:}'",
"f'{lambda :}'",
"f'{+ lambda:None}'",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing the other cases?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved them up to the check for the specialized error message, since these now raise the "parenthesize your lambdas" error.

@sunmy2019

@pablogsal @isidentical @sunmy2019 I'm okay with lambdas containing syntax errors emitting this error message as well. Anyone have objections on that?

I am good.

Is unlikely that people try lambdas in fstrings

Some reasonable usage would be passing as a param. Like f"{[*map(lambda x:x+1, some_iterable)]}" thought it's far from the best practice, and get parens anyway.

isidentical

carljm added a commit to carljm/cpython that referenced this pull request

Apr 24, 2023

carljm added a commit to carljm/cpython that referenced this pull request

Apr 24, 2023