-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Span for invalid escape sequence in multiline strings is wrong #116042
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
Comments
cc @pablogsal |
For comparison with Python 3.12.2: ❯ PYTHONWARNINGS=error python3.12 example.py
File "/private/tmp/example.py", line 1
a = """
^^^
SyntaxError: invalid escape sequence '\ ' And: ❯ PYTHONWARNINGS=error python3.12 example.py
File "/private/tmp/example.py", line 2
"""This function computes f.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid escape sequence '\ ' |
The problem here is that the parser and the tokeniser raise errors with granularity of tokens, and the whole string here is a token, so the parser cannot see inside the string to correctly point to it. I will try to see how hard is to point to the invalid escape and not the full token... |
…pes in the tokenizer
|
…pes in the tokenizer (pythonGH-116049) (cherry picked from commit 56eda25) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
…pes in the tokenizer (pythonGH-116049) (cherry picked from commit 56eda25) (cherry picked from commit 369704b) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Bug report
Bug description:
When running with
PYTHONWARNINGS=error python3.13 example.py
, i get the correct error that there is an invalid escape sequence, but the error span is located at the beginning of the string, not at the location of the actual error:Similarly, for docstrings, the opening quotes are marked, not the actual location:
This makes it look like the file is somehow corrupted or there is an encoding error rather than checking the actual docstring (astral-sh/uv#1928).
Python 3.13.0a1+
, installed with pyenv.I'd expected this to have been reported before, but searching for "invalid escape sequence strings", "escape sequence span" and "SyntaxWarning location" i didn't find anything matching.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: