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?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too