Bug Report
Assignment of a TypedDict into a Mapping with a wider type is not allowed despite being safe.
To Reproduce
from typing import TypedDict, Mapping
class TD(TypedDict):
a: str
b: int
type Data = Mapping[str, str | int]
value = TD(a="hello", b=123)
x: Data = value
Playground link
Expected Behavior
The assignment should be accepted. Every value of TD is a valid instance of Data, and being a mapping Data does not allow mutation.
Actual Behavior
main.py:11: error: Incompatible types in assignment (expression has type "TD", variable has type "Mapping[str, str | int]") [assignment]
Found 1 error in 1 file (checked 1 source file)
Your Environment
Running on python 3.13, latest mypy (1.14.1), default settings.
Bug Report
Assignment of a TypedDict into a Mapping with a wider type is not allowed despite being safe.
To Reproduce
Playground link
Expected Behavior
The assignment should be accepted. Every value of
TDis a valid instance ofData, and being a mappingDatadoes not allow mutation.Actual Behavior
Your Environment
Running on python 3.13, latest mypy (1.14.1), default settings.