Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.environ.pop doesn't work #45628

Closed
niemeyer mannequin opened this issue Oct 16, 2007 · 5 comments
Closed

os.environ.pop doesn't work #45628

niemeyer mannequin opened this issue Oct 16, 2007 · 5 comments

Comments

@niemeyer
Copy link
Mannequin

niemeyer mannequin commented Oct 16, 2007

BPO 1287
Nosy @birkenfeld

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2007-10-24.21:41:24.534>
created_at = <Date 2007-10-16.17:55:10.768>
labels = []
title = "os.environ.pop doesn't work"
updated_at = <Date 2007-10-26.18:31:03.769>
user = 'https://bugs.python.org/niemeyer'

bugs.python.org fields:

activity = <Date 2007-10-26.18:31:03.769>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = <Date 2007-10-24.21:41:24.534>
closer = 'georg.brandl'
components = []
creation = <Date 2007-10-16.17:55:10.768>
creator = 'niemeyer'
dependencies = []
files = []
hgrepos = []
issue_num = 1287
keywords = []
message_count = 5.0
messages = ['56500', '56505', '56731', '56745', '56807']
nosy_count = 3.0
nosy_names = ['georg.brandl', 'niemeyer', 'draghuram']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1287'
versions = ['Python 2.6', 'Python 2.5', 'Python 2.4', 'Python 2.3', 'Python 2.2.3', 'Python 2.2.2', 'Python 2.2.1', 'Python 2.2', 'Python 2.1.2', 'Python 2.1.1', 'Python 3.0']

@niemeyer
Copy link
Mannequin Author

niemeyer mannequin commented Oct 16, 2007

>> 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

@draghuram
Copy link
Mannequin

draghuram mannequin commented Oct 16, 2007

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)

@birkenfeld
Copy link
Member

Fixed in r58651 for 2.6.

@draghuram
Copy link
Mannequin

draghuram mannequin commented Oct 25, 2007

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):

@birkenfeld
Copy link
Member

You're right, fixed that in r58675.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant