When an f-string contains an = specifier, the characters before the equals sign are interpreted as if they were within a normal string. In particular, a backslash is always interpreted as starting an escape sequence, even when it doesn’t, which causes unexpected output.
Those results are misleading because the expressions printed before the equals signs are either syntax errors or do not match the values printed after the equals signs. I expected these results:
Even when the result is not so misleading, it would still be more helpful for debugging if the output kept the expression unmodified, instead of interpreting the escape sequences. For example, this:
Bug report
Bug description:
When an f-string contains an
=
specifier, the characters before the equals sign are interpreted as if they were within a normal string. In particular, a backslash is always interpreted as starting an escape sequence, even when it doesn’t, which causes unexpected output.Those results are misleading because the expressions printed before the equals signs are either syntax errors or do not match the values printed after the equals signs. I expected these results:
Even when the result is not so misleading, it would still be more helpful for debugging if the output kept the expression unmodified, instead of interpreting the escape sequences. For example, this:
would be better as this:
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
macOS