[issue45086] f-string unmatched ']'

Eric V. Smith report at bugs.python.org
Fri Sep 3 22:58:34 EDT 2021


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

I don't think it really makes a difference, but here's some background:

For f-strings, the parser itself does not break apart the f-string into (<text>, <expression>) parts. There's a custom parser (at https://github.com/python/cpython/blob/0b58e863df9970b290a4de90c67f9ac30c443817/Parser/string_parser.c#L837) which does that. Then the normal parser is used to parse the expression portion.

I think the error shown here is not in the expression parser, but in the fstring parser in fstring_find_expr(), at https://github.com/python/cpython/blob/0b58e863df9970b290a4de90c67f9ac30c443817/Parser/string_parser.c#L665

As Terry says, it's not incorrect to print the error show in this bug report.

To further diverge:

There's been talk about using the normal parser to pull apart the entire f-string, instead of using the two-pass version I mention above. But we've never gotten past just talking about it. There are pros and cons for doing it with the normal parser, but that's a discussion for a different forum.

----------

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


More information about the Python-bugs-list mailing list