Bug report
import os
def test_env(x):
print(f'setting X={x}')
os.environ['X'] = x
assert os.environ.get('X') == x, os.environ.get('X')
os.reload_environ()
assert os.environ.get('X') == x, os.environ.get('X')
test_env('1')
test_env('')
it is possible to set an empty environment variable on windows (via SetEnvironmentVariableW) -- but not from python's os.environ . there's more context here: pre-commit/pre-commit#3766 (comment) (due to _wputenv)
on linux (I only attempted with amd64 ubuntu 26.04) the script above succeeds -- on windows it fails with the following:
>python t.py
setting X=1
setting X=
Traceback (most recent call last):
File "C:\Users\asott\workspace\t.py", line 11, in <module>
test_env('')
~~~~~~~~^^^^
File "C:\Users\asott\workspace\t.py", line 8, in test_env
assert os.environ.get('X') == x, os.environ.get('X')
^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None
note also that this bug also results in os.environ diverging from the real environment (line 8 above is an assertion failure only after os.reload_environ())
note that I've only marked "3.14" as the version I tested on -- I suspect this also affects mainline but I do not have an easy way to build on the machine I'm working on at the moment
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Bug report
it is possible to set an empty environment variable on windows (via
SetEnvironmentVariableW) -- but not from python'sos.environ. there's more context here: pre-commit/pre-commit#3766 (comment) (due to_wputenv)on linux (I only attempted with amd64 ubuntu 26.04) the script above succeeds -- on windows it fails with the following:
note also that this bug also results in
os.environdiverging from the real environment (line 8 above is an assertion failure only afteros.reload_environ())note that I've only marked "3.14" as the version I tested on -- I suspect this also affects mainline but I do not have an easy way to build on the machine I'm working on at the moment
CPython versions tested on:
3.14
Operating systems tested on:
Windows