-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Closed
Copy link
Labels
bugmypy got something wrongmypy got something wrongtopic-type-contextType context / bidirectional inferenceType context / bidirectional inferencetopic-typed-dict
Description
In general, I'd assume x: T | U = e to succeed without error if e is assignable to either T or U. In the below code, the dict literal is not assignable to the typed dict TD, but it is assignable to dict[str, str]. Although the typed dict case does fail, I don't expect to see any type errors.
from typing import TypedDict
class TD(TypedDict):
x: int
x: TD | dict[str, str] = { "x": "foo" }Expected behavior: No error
Actual Behavior: Incompatible types (expression has type "str", TypedDict item "x" has type "int") [typeddict-item]
Mypy version used: 1.17.0 (playground)
Mypy command-line flags: playground defaults
Mypy configuration options from mypy.ini (and other config files): N/A
Python version used: 3.12
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-contextType context / bidirectional inferenceType context / bidirectional inferencetopic-typed-dict