[New-bugs-announce] [issue15373] copy.copy() does not properly copy os.environment

Hartmut Goebel report at bugs.python.org
Mon Jul 16 18:08:57 CEST 2012


New submission from Hartmut Goebel <h.goebel at crazy-compilers.com>:

Wehn copying os.environ usinf copy.copy(), any manipulation on the copied object will change os.environment, too.

$ python
Python 2.7.3 (default, Apr 22 2012, 07:46:58) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import copy, os
>>> os.environ['TITI']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'TITI'
>>> env = copy.copy(os.environ)
>>> env['TITI'] = 'in den Ferien'
>>> os.environ['TITI']
'in den Ferien'
>>> 

Strictly speaking, this is correct, as the os.environment class is meant to manipulate the environment in the background. But user's expectation is different: he thinks, manipulating the copied object is save and does not effect the environment.

----------
messages: 165631
nosy: htgoebel
priority: normal
severity: normal
status: open
title: copy.copy() does not properly copy os.environment
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15373>
_______________________________________


More information about the New-bugs-announce mailing list