The problem is that when there's the sequence \{ in the literal part of an f-string we call warn_invalid_escape_sequence which tries to emit a warning and, in doing so, is using the tokenizer to scan the first line and get the file encoding. The exact stack trace is the following:
We've created an endless loop when there's an invalid escape sequence in the first line of a file.
Minimal reproducer:
In
t.py
:When executing the file:
The problem is that when there's the sequence
\{
in the literal part of an f-string we callwarn_invalid_escape_sequence
which tries to emit a warning and, in doing so, is using the tokenizer to scan the first line and get the file encoding. The exact stack trace is the following: