Repository navigation
Conversation
|
Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate. Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors. This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness. Please read our guidelines for using AI tools. |
|
Why is there a comment that was changed? |
|
the old comment only describes skipping the file lookup when the start rule is not but you are right, updating only that sentence would have been sufficient. |
|
the problem is that the parser reads the source from disk even if the source was already provided directly to the fix is to skip the file lookup when the tokenizer already has the source. to verify this, codex ran a regression test with |
|
The issue is that I don't know whether this is really the appropriate fix. On the issue I asked to know what happened between Python versions to understand why I get different offsets but no one investigated it. I would really prefer that we first solve this quetsion before just fixing this like that. If I reread the docs, it says:
And thus, I would still expect that we should not necessarily read the input itself but the filename. So that's why I'd like to know why we have this issue in the first place and I'm going to close the PR. Please, avoid using agents to open PRs without reading the issue history first because not every issue has a settled conclusion or an actionable item. |
Fixes #127927.
An editor can pass an unsaved buffer and its filename to
ast.parse(). If the file on disk contains different text, the parser can quote the saved line and compute the wrong column. For example, withpasssaved inexample.py:The error points past the end of
passat column 6. With this change it points at the unexpected*in the supplied line, at column 16. This also corrects the diagnostic reported by Pyflakes when it checks this buffer.Only look up the line on disk when the tokenizer has no retained source. The regression test checks the error text, filename, line number, and character offsets for both a Unicode string and Latin-1 bytes.
Both inputs reproduced the bug on unmodified CPython. All nine targeted test modules passed on rerun. The first run had one timeout in the REPL history test, which also passed in isolation.
./python -m test -j2 test_exceptions test_syntax test_compile test_ast test_traceback test_tokenize test_codeop test_cmd_line_script test_pyreplOpenAI Codex helped reproduce the issue, write the fix and regression test, and verify the behavior with Pyflakes.
compile#127927