📜  python 为异构字典创建类型 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:54.521000             🧑  作者: Mango

代码示例1
from typing_extensions import TypedDict
class Point2D(TypedDict):
    x: int
    y: int
    label: str

a: Point2D = {'x': 1, 'y': 2, 'label': 'good'}  # OK
b: Point2D = {'z': 3, 'label': 'bad'}           # Fails type check

assert Point2D(x=1, y=2, label='first') == dict(x=1, y=2, label='first')