Skip to content

Prevent CO_FUTURE_BARRY_AS_BDFL from being applied with PyCF_MASK #123234

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

Open
scw opened this issue Aug 22, 2024 · 1 comment
Open

Prevent CO_FUTURE_BARRY_AS_BDFL from being applied with PyCF_MASK #123234

scw opened this issue Aug 22, 2024 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@scw
Copy link
Contributor

scw commented Aug 22, 2024

Bug report

Bug description:

When compiling Python strings with the PyCF_MASK, the CO_FUTURE_BARRY_AS_BDFL is included and will be applied to the statement. It would be preferable if the PEP 401 easter egg was not applied to code compiled with the PyCF_MASK compiler flag by default.

Example:

static const char code[] = "1 != 2";
static PyCompilerFlags compiler_flags = { PyCF_MASK | PyCF_SOURCE_IS_UTF8 };
PyObject* n = Py_CompileStringFlags(code, "<string>", Py_single_input, &compiler_flags);

Will result change the result to 1 <> 2.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS, Windows

@scw scw added the type-bug An unexpected behavior, bug, or error label Aug 22, 2024
@picnixz picnixz added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Aug 22, 2024
@duaneg
Copy link
Contributor

duaneg commented Jun 3, 2025

As the name suggests, PyCF_MASK is intended to be used as a bitwise mask. The existing uses are all along those lines, e.g. codeflags & PyCF_MASK or ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_COMPILE_MASK). Since CO_FUTURE_BARRY_AS_BDFL is apparently a real future flag, it needs to be included or that code will all break.

I don't think this is a bug: this is acting exactly as expected. I'm not sure why you would want to compile with all future flags, but if you want that except excluding one specific one you can always mask it off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants