[issue46260] Misleading SyntaxError on f-string

Eric V. Smith report at bugs.python.org
Wed Jan 5 06:29:25 EST 2022


Eric V. Smith <eric at trueblade.com> added the comment:

In fstring_find_expr, the code[0] that's checking for parens, braces, and brackets detects the closing paren without a matching open paren.

The error message isn't incorrect: if you added a matching open paren the code would compile:
>>> foo=lambda:0
>>> f'{foo()}'
'0'

So while the error might not be intuitive, it's not wrong.

0: https://github.com/python/cpython/blob/cae55542d23e606dde9819d5dadd7430085fcc77/Parser/string_parser.c#L664d

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46260>
_______________________________________


More information about the Python-bugs-list mailing list