diff --git a/testing/typing_checks.py b/testing/typing_checks.py index d15b3988b..80b8c9f82 100644 --- a/testing/typing_checks.py +++ b/testing/typing_checks.py @@ -4,11 +4,13 @@ This file is not executed, it is only checked by mypy to ensure that none of the code triggers any mypy errors. """ import contextlib +import sys from typing import Optional from typing_extensions import assert_type import pytest +from _pytest.monkeypatch import MonkeyPatch # Issue #7488. @@ -29,6 +31,16 @@ def check_parametrize_ids_callable(func) -> None: pass +# Issue #10999. +@pytest.mark.skipif(sys.version_info < (3, 8), reason="TypedDict introduced in Python 3.8") +def check_monkeypatch_typeddict(monkeypatch: MonkeyPatch) -> None: + from typing import TypedDict + + Foo = TypedDict("Foo", {"x": int, "y": float}) + a: Foo = {"x": 1, "y": 3.14} + monkeypatch.setitem("x", 2) + monkeypatch.delitem("y") + def check_raises_is_a_context_manager(val: bool) -> None: with pytest.raises(RuntimeError) if val else contextlib.nullcontext() as excinfo: pass