gh-57684: Add -P cmdline option and PYTHONSAFEPATH env var by vstinner · Pull Request #31542 · python/cpython (original) (raw)
I think that should be left for the future. Lets see if anyone actually wants it first. If we do go the route of aiming for a default flip in the future it might make sense.
Flipping the default can now be done by setting PYTHONSAFEPATH=1
system wide (or in the current shell).
The problem is that right now, if PYTHONSAFEPATH=1
is set, it's no longer possible to run programs which rely on the Python 3.10 behavior to load modules in the current directory (as Python freeze.py
tool), without having to modify the source code of these programs.
IMO command line options must have the priority over environment variables. Python does not provide command line options to disable the effect of all Python environment variables. For example, PYTHONUNBUFFERED=1
cannot be "undone" by a command line option. But the effect of this variable is limited: I'm not aware of any program broken by it.
The Python UTF-8 Mode is way more likely to cause compatibility issues and so -X utf8=0
can disable it on the command line: ignore PYTHONUTF8=1
env var.
We don't have to add -p
, but it makes PYTHONSAFEPATH=1
harder to use. The current workaround is to use -E
to ignore environment variables, or -I
(isolated mode) but this option has more effects (like not adding user site directories).