ty
ty copied to clipboard
Support inferring a call to `dict(...)` in TypedDict context
Originally reported at https://www.reddit.com/r/Python/comments/1podix2/comment/nuhhob3/
from typing import TypedDict
class TD(TypedDict):
x: int
t: TD = dict(x=1) # error: "Object of type `dict[str, int]` is not assignable to `TD`"
https://play.ty.dev/63687f42-6944-4a20-b04f-94a38b171e73
I'm going to try this over the weekend if that's ok :)
Despite the recommenation of not using mutable data structures as default input arguments, the following code snippet would not be working despite the fix. Is this expected?
def func(foo: TD = dict(x=1)) -> None:
...
(or even with the {"x": 1})