This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Redefine clear() for os.environ to use unsetenv() if possible
Type: behavior Stage:
Components: Library (Lib) Versions:
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: draghuram, georg.brandl, gvanrossum, martin.horcicka
Priority: normal Keywords: patch

Created on 2007-09-19 21:38 by martin.horcicka, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit martin.horcicka, 2007-09-19 21:38
Messages (5)
msg56048 - (view) Author: Martin Horcicka (martin.horcicka) Date: 2007-09-19 21:38
This patch makes os.environ.clear() to have the same effect as:

for name in os.environ.keys():
    del os.environ[name]

I believe that most people expect the effects to be the same anyway.

The practical benefit is a simpler redefinition of the whole environment
if desired (e.g. in scripts run via sudo on unix systems).
msg56060 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-09-20 17:20
Sounds like a good idea. Anyone care to check it in?
msg56061 - (view) Author: Raghuram Devarakonda (draghuram) (Python triager) Date: 2007-09-20 17:46
Shouldn't the first clear() in the patch say "del[key.upper()]" instead of "del[key]"? I also think
the patch should include doc change.
msg56063 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-09-20 17:52
On 9/20/07, Raghuram Devarakonda <> wrote:
> Shouldn't the first clear() in the patch say "del
>[key.upper()]" instead of "del[key]"? I also think
> the patch should include doc change.

I don't think so -- it goes over which means they are
already uppercase.

All of this would be unnecessary if clear() in UserDict were to be changed to

for key in self.keys(): del self[key]

But that's a much more pervasive change...
msg56064 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-09-20 17:59
Committed, incl. docs, as rev. 58221.
Date User Action Args
2022-04-11 14:56:27adminsetgithub: 45522
2007-09-20 17:59:03georg.brandlsetstatus: open -> closed
assignee: georg.brandl
resolution: accepted
messages: + msg56064
nosy: + georg.brandl
2007-09-20 17:52:17gvanrossumsetmessages: + msg56063
2007-09-20 17:46:04draghuramsetmessages: + msg56061
2007-09-20 17:20:11gvanrossumsetnosy: + gvanrossum
messages: + msg56060
2007-09-20 14:13:49draghuramsetnosy: + draghuram
2007-09-19 21:44:16jafosetpriority: normal
keywords: + patch
2007-09-19 21:38:22martin.horcickacreate