]> granicus.if.org Git - python/commitdiff
Bug #1287: make os.environ.pop() work as expected.
authorGeorg Brandl <georg@python.org>
Wed, 24 Oct 2007 21:40:38 +0000 (21:40 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 24 Oct 2007 21:40:38 +0000 (21:40 +0000)
Doc/library/os.rst
Lib/os.py
Misc/NEWS

index bc4cf4284a0cdf4d2e48f5777208024bb95bcc29..0e467411446203b4e0d65fc5828aa85558870b14 100644 (file)
@@ -118,10 +118,11 @@ process and user.
    If the platform supports the :func:`unsetenv` function, you can delete items in
    this mapping to unset environment variables. :func:`unsetenv` will be called
    automatically when an item is deleted from ``os.environ``, and when
-   :meth:`os.environ.clear` is called.
+   one of the :meth:`pop` or :meth:`clear` methods is called.
 
    .. versionchanged:: 2.6
-      Also unset environment variables when calling :meth:`os.environ.clear`.
+      Also unset environment variables when calling :meth:`os.environ.clear`
+      and :meth:`os.environ.pop`.
 
 
 .. function:: chdir(path)
index 7d21763603ed08b50ac9b6323d51233b8fea2c5b..ccc11f49de445f7c87411996da7e0ea9fa9b17fc 100644 (file)
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -450,6 +450,9 @@ else:
                     for key in self.data.keys():
                         unsetenv(key)
                         del self.data[key]
+                def pop(self, key, *args):
+                    unsetenv(key)
+                    return self.data.pop(key, *args)
             def has_key(self, key):
                 return key.upper() in self.data
             def __contains__(self, key):
@@ -511,6 +514,9 @@ else:
                     for key in self.data.keys():
                         unsetenv(key)
                         del self.data[key]
+                def pop(self, key, *args):
+                    unsetenv(key)
+                    return self.data.pop(key, *args)
             def copy(self):
                 return dict(self)
 
index 683bef06aa6343241e281e4e633f50bc74b73871..be6b6ff6842c0224bf8dc8f1702acae113c2388e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -274,11 +274,14 @@ Core and builtins
 Library
 -------
 
+- Issues #1181, #1287: unsetenv() is now called when the os.environ.pop()
+  and os.environ.clear() methods are used.
+
 - ctypes will now work correctly on 32-bit systems when Python is
   configured with --with-system-ffi.
 
 - Patch #1203: ctypes now does work on OS X when Python is built with
-  --disable-toolbox-glue
+  --disable-toolbox-glue.
 
 - collections.deque() now supports a "maxlen" argument.