Skip to content
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

bpo-45848: Allow the parser to get error lines from encoded files #29646

Merged
merged 1 commit into from Nov 20, 2021

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Nov 19, 2021

error_line = PyErr_ProgramTextObject(p->tok->filename, (int) lineno);
else if (p->start_rule == Py_file_input) {
error_line = _PyErr_ProgramDecodedTextObject(p->tok->filename,
(int) lineno, p->tok->encoding);
Copy link
Contributor

@ambv ambv Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏻

@ambv ambv merged commit fdcc46d into python:main Nov 20, 2021
12 checks passed
@miss-islington
Copy link
Contributor

miss-islington commented Nov 20, 2021

Thanks @pablogsal for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒🤖

@miss-islington
Copy link
Contributor

miss-islington commented Nov 20, 2021

Sorry, @pablogsal and @ambv, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker fdcc46d9554094994f78bedf6dc9220e5d5ee668 3.10

@miss-islington
Copy link
Contributor

miss-islington commented Nov 20, 2021

Sorry @pablogsal and @ambv, I had trouble checking out the 3.9 backport branch.
Please backport using cherry_picker on command line.
cherry_picker fdcc46d9554094994f78bedf6dc9220e5d5ee668 3.9

ambv pushed a commit to ambv/cpython that referenced this pull request Nov 20, 2021
…les (pythonGH-29646).

(cherry picked from commit fdcc46d)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
@bedevere-bot
Copy link

bedevere-bot commented Nov 20, 2021

GH-29661 is a backport of this pull request to the 3.10 branch.

@ambv
Copy link
Contributor

ambv commented Nov 20, 2021

@pablogsal, backporting this to 3.9 is more involved as the parser is much simpler in this case, see:

if (p->start_rule == Py_file_input) {
error_line = PyErr_ProgramTextObject(p->tok->filename, (int) lineno);
}
if (!error_line) {
Py_ssize_t size = p->tok->inp - p->tok->buf;
error_line = PyUnicode_DecodeUTF8(p->tok->buf, size, "replace");
if (!error_line) {
goto error;
}
}

There is no assert that failed in the original bug report, there is no get_error_line function, there is no fp_interactive, there is no TestCase under which you put the new test in.

Let me know if you'd like me to still proceed with the backport. The current 3.11 crasher doesn't produce too terrible of a result under 3.9:

❯ python3.9 /tmp/crash.py
  File "/tmp/crash.py", line 3

    ^
SyntaxError: unexpected EOF while parsing

ambv added a commit that referenced this pull request Nov 20, 2021
…les (GH-29646) (GH-29661)

(cherry picked from commit fdcc46d)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
@pablogsal
Copy link
Member Author

pablogsal commented Nov 20, 2021

@pablogsal, backporting this to 3.9 is more involved as the parser is much simpler in this case, see:

if (p->start_rule == Py_file_input) {
error_line = PyErr_ProgramTextObject(p->tok->filename, (int) lineno);
}
if (!error_line) {
Py_ssize_t size = p->tok->inp - p->tok->buf;
error_line = PyUnicode_DecodeUTF8(p->tok->buf, size, "replace");
if (!error_line) {
goto error;
}
}

There is no assert that failed in the original bug report, there is no get_error_line function, there is no fp_interactive, there is no TestCase under which you put the new test in.

Let me know if you'd like me to still proceed with the backport. The current 3.11 crasher doesn't produce too terrible of a result under 3.9:

❯ python3.9 /tmp/crash.py
  File "/tmp/crash.py", line 3

    ^
SyntaxError: unexpected EOF while parsing

Thanks @ambv ! I will give it a go but as this doesn't crash in 3.9 I'm ok to just leave as is, as in this way we can also avoid potential unintended side effects in 3.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants