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:
Bénédikt Tran 2025-03-16 14:09:33 +01:00 committed by GitHub
parent 9558d22ac3
commit 3185e3115c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 38 additions and 45 deletions

View file

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