[issue46260] Misleading SyntaxError on f-string

William Navaraj report at bugs.python.org
Wed Jan 5 11:43:18 EST 2022


William Navaraj <williamnavaraj at gmail.com> added the comment:

@Eric Smith,Thanks for explaining the intuition behind this statement. I agree. Just to avoid ambiguity we could add

"f-string: unmatched '%c' - no matching open parenthesis or missing '}'"

The only possibility at nested_depth==0 line 665 is either of those because of the check in line 559 i.e. assert(**str == '{')
https://github.com/python/cpython/blob/cae55542d23e606dde9819d5dadd7430085fcc77/Parser/string_parser.c#L559

Will help folks to look backwards (close to open as well) than forwards (open to close) as in Matt's case which is also a valid interpretation where there is an opening paren outside the f-string.  

or simply

"f-string: unmatched '%c' or missing '}'" will also do.

----------
nosy: +williamnavaraj

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


More information about the Python-bugs-list mailing list