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-45822: Respect PEP 263's coding cookies in the parser even if flags are not provided #29582

Merged
merged 1 commit into from
Nov 16, 2021

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Nov 16, 2021

Copy link
Member

@ammaraskar ammaraskar left a 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:

int iflags = PARSER_FLAGS(flags);

cpython/Python/pythonrun.c

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;
}

@miss-islington
Copy link
Contributor

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

@miss-islington
Copy link
Contributor

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

@miss-islington miss-islington self-assigned this Nov 16, 2021
@miss-islington
Copy link
Contributor

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

if (the_string == NULL) {
return NULL;
}
return Py_CompileString(the_string, "blech", Py_file_input);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return Py_CompileString(the_string, "blech", Py_file_input);
return Py_CompileString(the_string, "<string>", Py_file_input);

So it matches the test.

pablogsal added a commit to pablogsal/cpython that referenced this pull request Nov 16, 2021
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Nov 16, 2021
@bedevere-bot
Copy link

GH-29585 is a backport of this pull request to the 3.9 branch.

pablogsal added a commit to pablogsal/cpython that referenced this pull request Nov 16, 2021
… if flags are not provided (pythonGH-29582).

(cherry picked from commit da20d74)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Nov 16, 2021
@bedevere-bot
Copy link

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):
Copy link
Member

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.

Copy link
Member Author

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

ambv pushed a commit that referenced this pull request Nov 17, 2021
… if flags are not provided (GH-29582) (GH-29586)

(cherry picked from commit da20d74)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
ambv pushed a commit that referenced this pull request Nov 17, 2021
remykarem pushed a commit to remykarem/cpython that referenced this pull request Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants