mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-131277: allow EnvironmentVarGuard
to unset more than one environment variable at once (#131280)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
9558d22ac3
commit
3185e3115c
15 changed files with 38 additions and 45 deletions
|
@ -720,9 +720,10 @@ else:
|
|||
|
||||
|
||||
class EnvironmentVarGuard(collections.abc.MutableMapping):
|
||||
"""Class to help protect the environment variable properly.
|
||||
|
||||
"""Class to help protect the environment variable properly. Can be used as
|
||||
a context manager."""
|
||||
Can be used as a context manager.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._environ = os.environ
|
||||
|
@ -756,8 +757,10 @@ class EnvironmentVarGuard(collections.abc.MutableMapping):
|
|||
def set(self, envvar, value):
|
||||
self[envvar] = value
|
||||
|
||||
def unset(self, envvar):
|
||||
del self[envvar]
|
||||
def unset(self, envvar, /, *envvars):
|
||||
"""Unset one or more environment variables."""
|
||||
for ev in (envvar, *envvars):
|
||||
del self[ev]
|
||||
|
||||
def copy(self):
|
||||
# We do what os.environ.copy() does.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue