diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index c968e5cc6923..882d748afaea 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -932,7 +932,8 @@ def match_typeddict_call_with_dict( kwargs: list[tuple[Expression | None, Expression]], context: Context, ) -> bool: - result = self.validate_typeddict_kwargs(kwargs=kwargs, callee=callee) + with self.msg.filter_errors(): + result = self.validate_typeddict_kwargs(kwargs=kwargs, callee=callee) if result is not None: validated_kwargs, _ = result return callee.required_keys <= set(validated_kwargs.keys()) <= set(callee.items.keys()) diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index c74ae96d7763..17a1fea22ef0 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -941,6 +941,18 @@ c: Union[A, B] = {'@type': 'a-type', 'value': 'Test'} # E: Type of TypedDict is [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] +[case testTypedDictUnionWithNonTypedDictLiteralKey] +from typing import Union, TypedDict + +class Foo(TypedDict): + some: str + name: str + +baz: Union[Foo, dict[int, float]] = {1: 5.2} +baz2: Union[Foo, dict[int, float]] = {'some': 'x', 'name': 'y'} +[builtins fixtures/dict.pyi] +[typing fixtures/typing-typeddict.pyi] + -- Use dict literals [case testTypedDictDictLiterals]