classification
Title: os.environ.pop doesn't work
Type: Stage:
Components: Versions: Python 3.0, Python 2.4, Python 2.3, Python 2.2.3, Python 2.6, Python 2.2.2, Python 2.5, Python 2.2.1, Python 2.2, Python 2.1.2, Python 2.1.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: draghuram, georg.brandl, niemeyer
Priority: normal Keywords:

Created on 2007-10-16 17:55 by niemeyer, last changed 2007-10-26 18:31 by georg.brandl. This issue is now closed.

Messages (5)
msg56500 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2007-10-16 17:55
>>> import os
>>> os.system("echo $ASD")

0
>>> os.environ["ASD"] = "asd"
>>> os.system("echo $ASD")
asd
0
>>> os.environ.pop("ASD")
'asd'
>>> os.system("echo $ASD")
asd
0
msg56505 - (view) Author: Raghuram Devarakonda (draghuram) Date: 2007-10-16 19:07
The following patch solves the problem (with the latest from trunk). I
only tested on Linux. I couldn't reproduce the problem with latest py3k
(again, on Linux).

===================================================================
--- Lib/os.py   (revision 58221)
+++ Lib/os.py   (working copy)
@@ -446,6 +446,9 @@
                 def __delitem__(self, key):
                     unsetenv(key)
                     del self.data[key.upper()]
+                def pop(self, key):
+                    unsetenv(key)
+                    return UserDict.IterableUserDict.pop(self, key)
                 def clear(self):
                     for key in self.data.keys():
                         unsetenv(key)
@@ -513,6 +516,9 @@
                         del self.data[key]
             def copy(self):
                 return dict(self)
+            def pop(self, key):
+                unsetenv(key)
+                return UserDict.IterableUserDict.pop(self, key)
 
 
     environ = _Environ(environ)
msg56731 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-10-24 21:41
Fixed in r58651 for 2.6.
msg56745 - (view) Author: Raghuram Devarakonda (draghuram) Date: 2007-10-25 13:54
After reading the change, I think one more small change may be required.

Index: Lib/os.py
===================================================================
--- Lib/os.py   (revision 58654)
+++ Lib/os.py   (working copy)
@@ -452,7 +452,7 @@
                         del self.data[key]
                 def pop(self, key, *args):
                     unsetenv(key)
-                    return self.data.pop(key, *args)
+                    return self.data.pop(key.upper(), *args)
             def has_key(self, key):
                 return key.upper() in self.data
             def __contains__(self, key):
msg56807 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-10-26 18:31
You're right, fixed that in r58675.
History
Date User Action Args
2007-10-26 18:31:03georg.brandlsetmessages: + msg56807
2007-10-25 13:54:58draghuramsetmessages: + msg56745
2007-10-24 21:41:24georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
resolution: fixed
messages: + msg56731
2007-10-16 19:07:05draghuramsetnosy: + draghuram
messages: + msg56505
2007-10-16 17:55:48niemeyersetmessages: + msg56500
2007-10-16 17:55:10niemeyercreate