-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-123969: refactor _PyErr_RaiseSyntaxError and _PyErr_EmitSyntaxWarning out of compiler #123972
Conversation
…axWarning out of compiler
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change by itself feels unnecessary, but I'm guessing you'll use these functions in more places in the future. Would it make sense to change some of those other places in this PR so you can know whether the API will work for all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Python/errors.c
Outdated
text = Py_NewRef(Py_None); | ||
} | ||
PyObject *args = Py_BuildValue("O(OiiOii)", msg, filename, | ||
lineno, col_offset + 1, text, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still do the +1 here, so at the end, it's +2 which is wrong, no?
I want to use it in order to raise the |
I prefer a separated PR just for these two PyErr functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Is the +1
on col_offset needed because compile.c counts starting at 0 and the displayed error starts counting at 1?
SyntaxError is defined to start at 1: https://docs.python.org/3/library/exceptions.html#SyntaxError |
The location comes from the AST, where it starts at 0. |
…axWarning out of compiler (python#123972)
These were local to the compiler, but after the splitting it would be good to be able to use them without needing to pass in a compiler struct (which is only used for the filename).
Fixes #123969.