You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PYTHONDONTWRITEBYTECODE documentation is incorrect #143134
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:
intdont_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".
The documented behavior is the initial behavior. Since the change is not documented, it was not intentional change.
It seems that it was changed in a7368ac (bpo-32030). Since it was so long ago, we cannot longer consider it a behavior bug, but a documentation bug. The documentation should be made reflecting the current behavior, and the versionchanged directives should be added.
For all of these variables check whether setting the variable to "0" actually changes the behavior or only sys.flags. If it only changes the latter, then this is the bug in the code, otherwise the bug is in the documentation.
Activity
StanFromIreland commentedon Dec 24, 2025
The same can be said for several others:
Javed-Shekh777 commentedon Dec 24, 2025
Hi, I’d like to work on this documentation fix and submit a PR.
serhiy-storchaka commentedon Dec 24, 2025
The documented behavior is the initial behavior. Since the change is not documented, it was not intentional change.
It seems that it was changed in a7368ac (bpo-32030). Since it was so long ago, we cannot longer consider it a behavior bug, but a documentation bug. The documentation should be made reflecting the current behavior, and the
versionchangeddirectives should be added.cc @vstinner
vstinner commentedon Dec 24, 2025
Other environment variables are impacted (they also use
_Py_get_env_flag()):StanFromIreland commentedon Dec 24, 2025
IIUC Serhiy correct (I'm not quite sure why) the behaviour of this one is correct #143135 (comment)
serhiy-storchaka commentedon Dec 24, 2025
For all of these variables check whether setting the variable to "0" actually changes the behavior or only
sys.flags. If it only changes the latter, then this is the bug in the code, otherwise the bug is in the documentation.