strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Idea: Support for TypedDicts

Open patrick91 opened this issue 3 years ago • 0 comments
trafficstars

Python's type system provides a way to type dictionaries, using TypedDict, for example:

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')

I wonder if we should allow people to use TypedDicts too, maybe using a new decorator. I'm not sure if it is worth the effort, but we do allow people do customise the default resolver to return dictionaries, maybe this could be a better approach in that direction?

patrick91 avatar Sep 21 '22 07:09 patrick91