-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
F-string error recovery within list parsing is good but it breaks when it's within a parenthesized context.
For example,
bad_function_call(
param1=f'test
param2='test'
)The re-lexing will reduce the nesting level when recovering from an unclosed f-string but the lexer isn't in an expression element so the nesting level it reduced is the one from the outer context. This means that it'll emit an Indent token before param2 which is incorrect.
Another example is when the parser is recovering from within a format spec,
bad_function_call(
param1=f'test{x:.3f,
param2='test'
)Here, the parser uses the same list parsing logic for parsing both the outer f-string elements and the ones in the format specifier. This means that when it tries to recover from an unclosed f-string, it reduces the nesting level twice (1) when re-lexing from the format spec and (2) when re-lexing from the outer f-string.
Todo
- Reduce the nesting level only if the parser is recovering from within an expression element of an f-string (
fstring.is_in_expression) - Avoid calling into re-lexing when recovering from the format specifier. Let the recovery from the outer context (f-string) take care of that.