summaryrefslogtreecommitdiffstats
path: root/pre_commit/envcontext.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-11-03 06:17:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2020-11-03 06:17:38 +0000
commite3829cc5d067599ba8416821f67a936b8b3dd368 (patch)
tree5b1b408e23e36868aeb04e934a51feaec86cd145 /pre_commit/envcontext.py
parentReleasing debian version 2.7.1-1. (diff)
downloadpre-commit-e3829cc5d067599ba8416821f67a936b8b3dd368.tar.xz
pre-commit-e3829cc5d067599ba8416821f67a936b8b3dd368.zip
Merging upstream version 2.8.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/envcontext.py')
-rw-r--r--pre_commit/envcontext.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/pre_commit/envcontext.py b/pre_commit/envcontext.py
index 16d3d15..4ab0d8c 100644
--- a/pre_commit/envcontext.py
+++ b/pre_commit/envcontext.py
@@ -2,13 +2,12 @@ import contextlib
import enum
import os
from typing import Generator
+from typing import MutableMapping
from typing import NamedTuple
from typing import Optional
from typing import Tuple
from typing import Union
-from pre_commit.util import EnvironT
-
class _Unset(enum.Enum):
UNSET = 1
@@ -27,7 +26,7 @@ ValueT = Union[str, _Unset, SubstitutionT]
PatchesT = Tuple[Tuple[str, ValueT], ...]
-def format_env(parts: SubstitutionT, env: EnvironT) -> str:
+def format_env(parts: SubstitutionT, env: MutableMapping[str, str]) -> str:
return ''.join(
env.get(part.name, part.default) if isinstance(part, Var) else part
for part in parts
@@ -37,7 +36,7 @@ def format_env(parts: SubstitutionT, env: EnvironT) -> str:
@contextlib.contextmanager
def envcontext(
patch: PatchesT,
- _env: Optional[EnvironT] = None,
+ _env: Optional[MutableMapping[str, str]] = None,
) -> Generator[None, None, None]:
"""In this context, `os.environ` is modified according to `patch`.
@@ -50,7 +49,7 @@ def envcontext(
replaced with the previous environment
"""
env = os.environ if _env is None else _env
- before = env.copy()
+ before = dict(env)
for k, v in patch:
if v is UNSET: