Check TypedDict items [typeddict-item]
When constructing a TypedDict
object, mypy checks that each key and value is compatiblewith the TypedDict
type that is inferred from the surrounding context.
Example:
- from typing_extensions import TypedDict
- class Point(TypedDict):
- x: int
- y: int
- # Error: Incompatible types (expression has type "float",
- # TypedDict item "x" has type "int") [typeddict-item]
- p: Point = {'x': 1.2, 'y': 4}