New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
f-string assert is too restrictive #74867
Comments
>>> eval("f'\\\n'")
python: Python/ast.c:4906: FstringParser_ConcatFstring: Assertion `!state->last_str || PyUnicode_GET_LENGTH(state->last_str) != 0' failed.
[2] 12810 abort (core dumped) ./python The problem is that some literal strings are zero length. The assert can be deleted. |
Before the patch, eval("f'\\\n'") gives me the same assertion failure, with an IDLE freeze instead of core dump equivalent, but is seems that the string should be of length 2. >>> len('\\\n')
2
>>> len(f'\\\n')
2 |
Terry: The eval is important. The bug was in evaluating an f-string that consisted of two bytes: a backslash followed by a newline. And just as: It's the second one that was throwing the assertion. The parser was seeing these bytes: Without the eval, I can't think of a way to have a string consisting of those two bytes, but I assume someone who's trickier than I can come up with a way. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: