MutableMapping -> Mapping
This commit is contained in:
parent
a5a8e35bc3
commit
8bc212caf7
|
@ -2,13 +2,12 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import typing
|
|
||||||
import warnings
|
import warnings
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
from typing import List
|
from typing import List
|
||||||
from typing import MutableMapping
|
from typing import Mapping
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import overload
|
from typing import overload
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
@ -130,13 +129,7 @@ class MonkeyPatch:
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._setattr: List[Tuple[object, str, object]] = []
|
self._setattr: List[Tuple[object, str, object]] = []
|
||||||
self._setitem: List[
|
self._setitem: List[Tuple[Mapping[Any, Any], object, object]] = []
|
||||||
Tuple[
|
|
||||||
Union[MutableMapping[Any, Any], "typing.TypedDict[Any, Any]"],
|
|
||||||
object,
|
|
||||||
object,
|
|
||||||
]
|
|
||||||
] = []
|
|
||||||
self._cwd: Optional[str] = None
|
self._cwd: Optional[str] = None
|
||||||
self._savesyspath: Optional[List[str]] = None
|
self._savesyspath: Optional[List[str]] = None
|
||||||
|
|
||||||
|
@ -297,21 +290,12 @@ class MonkeyPatch:
|
||||||
self._setattr.append((target, name, oldval))
|
self._setattr.append((target, name, oldval))
|
||||||
delattr(target, name)
|
delattr(target, name)
|
||||||
|
|
||||||
def setitem(
|
def setitem(self, dic: Mapping[K, V], name: K, value: V) -> None:
|
||||||
self,
|
|
||||||
dic: Union[MutableMapping[K, V], "typing.TypedDict[K, V]"],
|
|
||||||
name: K,
|
|
||||||
value: V,
|
|
||||||
) -> None:
|
|
||||||
"""Set dictionary entry ``name`` to value."""
|
"""Set dictionary entry ``name`` to value."""
|
||||||
self._setitem.append((dic, name, dic.get(name, notset)))
|
self._setitem.append((dic, name, dic.get(name, notset)))
|
||||||
dic[name] = value
|
dic[name] = value
|
||||||
|
|
||||||
def delitem(
|
def delitem(self, dic: Mapping[K, V], name: K, raising: bool = True,
|
||||||
self,
|
|
||||||
dic: Union[MutableMapping[K, V], "typing.TypedDict[K, V]"],
|
|
||||||
name: K,
|
|
||||||
raising: bool = True,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Delete ``name`` from dict.
|
"""Delete ``name`` from dict.
|
||||||
|
|
||||||
|
@ -353,7 +337,7 @@ class MonkeyPatch:
|
||||||
Raises ``KeyError`` if it does not exist, unless ``raising`` is set to
|
Raises ``KeyError`` if it does not exist, unless ``raising`` is set to
|
||||||
False.
|
False.
|
||||||
"""
|
"""
|
||||||
environ: MutableMapping[str, str] = os.environ
|
environ: Mapping[str, str] = os.environ
|
||||||
self.delitem(environ, name, raising=raising)
|
self.delitem(environ, name, raising=raising)
|
||||||
|
|
||||||
def syspath_prepend(self, path) -> None:
|
def syspath_prepend(self, path) -> None:
|
||||||
|
|
Loading…
Reference in New Issue