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
PYTHONDONTWRITEBYTECODE and PYTHONOPTIMIZE have no effect #76026
Comments
Setting PYTHONDONTWRITEBYTECODE doesn't seem to have an effect in Python 3.7.0a2: $ python -V
Python 3.7.0a2
$ env PYTHONDONTWRITEBYTECODE=1 python -c 'import sys; print(sys.dont_write_bytecode)'
False |
Looks like PYTHONOPTIMIZE has no effect either: $ python -V
Python 3.7.0a2
$ env PYTHONOPTIMIZE=1 python -c 'import sys; print(sys.flags.optimize)'
0 |
Huh, it appears the tests for these features are relying solely on the command line options, and not checking that the environment variables are also setting the flags properly. We should be able to account for that omission with a single new test in As far as what's actually going wrong goes, it's this sequence of events in Py_Main:
_Py_InitializeCore is setting the internal flags appropriately based on the runtime environment, but then Py_Main is stomping over those environmental settings with the settings from the command line. Historically, these operations happened the other way around, so it was solely up to the code reading the environment variables to ensure they played nice with each other. Now the command line processing logic needs to be updated to also ensure that it only ever increases these values and never reduces them. |
We could still use some more comprehensive test cases for the env var handling and the way that interacts with the command line settings, but the merged PR includes at least a rudimentary check for the four that directly affect sys.flags without any tricky side effects (PYTHONDEBUG, PYTHONVERBOSE, PYTHONOPTIMIZE, PYTHONDONTWRITEBYTECODE). |
Cross-linking to the work-in-progress RFE that introduced the error: https://bugs.python.org/issue22257 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: