diff --git a/changelog/10999.bugfix.rst b/changelog/10999.bugfix.rst index 1eeae02b1..08c68da01 100644 --- a/changelog/10999.bugfix.rst +++ b/changelog/10999.bugfix.rst @@ -1 +1 @@ -Fixed bug where monkeypatch setitem/delitem type annotations didn't support typing.TypedDict. +The `monkeypatch` `setitem`/`delitem` type annotations now allow `TypedDict` arguments. diff --git a/src/_pytest/monkeypatch.py b/src/_pytest/monkeypatch.py index 6d63da443..c4a72e49d 100644 --- a/src/_pytest/monkeypatch.py +++ b/src/_pytest/monkeypatch.py @@ -295,12 +295,7 @@ class MonkeyPatch: self._setitem.append((dic, name, dic.get(name, notset))) dic[name] = value - def delitem( - self, - dic: Mapping[K, V], - name: K, - raising: bool = True, - ) -> None: + def delitem(self, dic: Mapping[K, V], name: K, raising: bool = True) -> None: """Delete ``name`` from dict. Raises ``KeyError`` if it doesn't exist, unless ``raising`` is set to @@ -341,7 +336,7 @@ class MonkeyPatch: Raises ``KeyError`` if it does not exist, unless ``raising`` is set to False. """ - environ: Mapping[str, str] = os.environ + environ: MutableMapping[str, str] = os.environ self.delitem(environ, name, raising=raising) def syspath_prepend(self, path) -> None: