-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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-45822: Respect PEP 263's coding cookies in the parser even if flags are not provided #29582
Conversation
…gs are not provided
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.
Link to previous code for reference:
Line 1447 in fd206b6
int iflags = PARSER_FLAGS(flags); |
Lines 156 to 171 in fd206b6
/* compute parser flags based on compiler flags */ | |
static int PARSER_FLAGS(PyCompilerFlags *flags) | |
{ | |
int parser_flags = 0; | |
if (!flags) | |
return 0; | |
if (flags->cf_flags & PyCF_DONT_IMPLY_DEDENT) | |
parser_flags |= PyPARSE_DONT_IMPLY_DEDENT; | |
if (flags->cf_flags & PyCF_IGNORE_COOKIE) | |
parser_flags |= PyPARSE_IGNORE_COOKIE; | |
if (flags->cf_flags & CO_FUTURE_BARRY_AS_BDFL) | |
parser_flags |= PyPARSE_BARRY_AS_BDFL; | |
if (flags->cf_flags & PyCF_TYPE_COMMENTS) | |
parser_flags |= PyPARSE_TYPE_COMMENTS; | |
return parser_flags; | |
} |
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
Sorry, @pablogsal, I could not cleanly backport this to |
Sorry @pablogsal, I had trouble checking out the |
if (the_string == NULL) { | ||
return NULL; | ||
} | ||
return Py_CompileString(the_string, "blech", Py_file_input); |
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.
return Py_CompileString(the_string, "blech", Py_file_input); | |
return Py_CompileString(the_string, "<string>", Py_file_input); |
So it matches the test.
…gs are not provided (pythonGH-29582) (cherry picked from commit da20d74)
GH-29585 is a backport of this pull request to the 3.9 branch. |
… if flags are not provided (pythonGH-29582). (cherry picked from commit da20d74) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
GH-29586 is a backport of this pull request to the 3.10 branch. |
@@ -1017,6 +1017,14 @@ def test_state_access(self): | |||
with self.assertRaises(TypeError): | |||
increment_count(1, 2, 3) | |||
|
|||
def test_Py_CompileString(self): |
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.
Actually, while backporting this patch to our internal 3.9, I noticed this test method is in the wrong class. It should be in the CAPITest class.
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.
I will submit a fix today
…gs are not provided (pythonGH-29582)
https://bugs.python.org/issue45822