monkeypatch: add support for TypedDict

This commit is contained in:
Adam J. Stewart 2023-05-13 16:10:35 -05:00
parent 76d15231f5
commit dc7a4503ab
No known key found for this signature in database
GPG Key ID: C66C0675661156FC
1 changed files with 3 additions and 3 deletions

View File

@ -129,7 +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[Tuple[MutableMapping[Any, Any], object, object]] = [] self._setitem: List[Tuple[Union[MutableMapping[Any, Any], "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
@ -290,12 +290,12 @@ class MonkeyPatch:
self._setattr.append((target, name, oldval)) self._setattr.append((target, name, oldval))
delattr(target, name) delattr(target, name)
def setitem(self, dic: MutableMapping[K, V], name: K, value: V) -> None: def setitem(self, dic: Union[MutableMapping[K, V], "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(self, dic: MutableMapping[K, V], name: K, raising: bool = True) -> None: def delitem(self, dic: Union[MutableMapping[K, V], "TypedDict[K, V"], name: K, raising: bool = True) -> None:
"""Delete ``name`` from dict. """Delete ``name`` from dict.
Raises ``KeyError`` if it doesn't exist, unless ``raising`` is set to Raises ``KeyError`` if it doesn't exist, unless ``raising`` is set to