[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

Irit Katriel report at bugs.python.org
Sat Aug 28 06:54:11 EDT 2021


Irit Katriel <iritkatriel at gmail.com> added the comment:

They keys are checked now, so I think this is resolved.  (Tested on windows and Mac).

>>> os.environ[''] = 'X'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/iritkatriel/src/cpython/Lib/os.py", line 684, in __setitem__
    putenv(key, value)
    ^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument

>>> os.environ['a=b'] = 'c'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/iritkatriel/src/cpython/Lib/os.py", line 684, in __setitem__
    putenv(key, value)
    ^^^^^^^^^^^^^^^^^^
ValueError: illegal environment variable name

----------
nosy: +iritkatriel
resolution:  -> out of date
status: open -> pending

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue20658>
_______________________________________


More information about the Python-bugs-list mailing list