Closed sh-at-cs closed 2 weeks ago
This is correct because TypedDict is invariant in its value types. It would be legal to write outer_super["inner"] = {"x": 3}
, making the value incompatible with InnerSub
.
https://peps.python.org/pep-0705/ will address this.
Bug Report
When a structural subtyping relation between two "inner"
TypedDict
s should cause "outer"TypedDict
s that contain them (and only them) to be subtypes of each other as well, Mypy fails to understand this and reports that the outer subtype is incompatible with the outer supertype.To Reproduce
Expected Behavior
No type errors are reported by Mypy because
OuterSub
is a structural subtype ofOuterSuper
.Actual Behavior
Mypy reports an error:
Your Environment
mypy.ini
(and other config files): NoneNow that it has turned out this is expected behavior (see comment below), a few keywords to let other people find this issue more easily: covariance, variance, invariance, covariant