python / python/cpython

PYTHONDONTWRITEBYTECODE documentation is incorrect

Open
#143,134 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Documentation

PYTHONDONTWRITEBYTECODE is documented in Doc/using/cmdline.rst as:

If this is set to a non-empty string, Python won't try to write .pyc files on the import of source modules.

This is incorrect. The variable is obtained in Python/initconfig.c as:

    int dont_write_bytecode = 0;
    _Py_get_env_flag(use_env, &dont_write_bytecode, "PYTHONDONTWRITEBYTECODE");
    if (dont_write_bytecode) {
        config->write_bytecode = 0;
    }

and _Py_get_env_flag reads the environment variable value as integer, treating non-integer string as 1. Specifically, this means that PYTHONDONTWRITEBYTECODE=0 will not suppress writing .pyc files, even though the environment variable is assigned a non-empty string "0".

Linked PRs
  • gh-143144

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 in Doc/using/cmdline.rst and compare the documented behavior with Python/initconfig.c, especially the _Py_get_env_flag call shown in the issue. Update the environment-variable description so its integer parsing and the PYTHONDONTWRITEBYTECODE=0 behavior are accurate; the documentation is done when the wording matches the implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.