python / python/cpython

Prevent CO_FUTURE_BARRY_AS_BDFL from being applied with PyCF_MASK

Open
#123,234 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CO_FUTURE_BARRY_AS_BDFL definition in Include/cpython/compile.h and trace how Py_CompileStringFlags handles PyCF_MASK. Reproduce the supplied C example on CPython main, then add or update coverage so PyCF_MASK no longer applies the PEP 401 behavior by default.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.