Terry J. Reedy <tjre...@udel.edu> added the comment:
Thank you Eric. I can see now that the actual process is a somewhat complicated mix of the simple options 1 and 2 I imagined above. It is like option 2, except that everything between '{' and '}' is partially parsed enough to create a format object. This is required to ignore quoted braces >>> f'{"}"' SyntaxError: f-string: expecting '}' and detect valid '!' and ':' markers. In that partial parsing, unmatched fences are detected and reported, while other syntax errors are not. If my option 1 above were true, the first example below would instead report the 'a a' error. >>> f'{a a' SyntaxError: f-string: expecting '}' >>> f'{a a]' SyntaxError: f-string: unmatched ']' >>> f'{a a}' SyntaxError: f-string: invalid syntax. Perhaps you forgot a comma? The second plausibly could, but outside of the f-string context, the error is the same. >>> a a] SyntaxError: unmatched ']' Greg, the fuller answer to your question is that the interpreter is only *required* to report that there is an error and some indication of where. "SyntaxError: invalid syntax" is the default. It may have once been all that was ever reported. A lot of recent effort has gone into adding detail into what is wrong and what the fix might be. But both additions sometimes involve choices that may not meet a particular person's expectation. Another person, expecting linear rather than nested parsing, might look at the first example above and ask whether the interpreter should be complaining about the 'a a' syntax error instead of the following lack of '}' f-string error. And I would not call it a bug if it were to do so in the future. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45086> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com