You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support more than just string literals with TypedDict indexing #7867
from mypy_extensions import TypedDict
T = TypedDict('T', {'a': float, 'b': float, 'c': float})
foo: T = {'a': 0.0, 'b': 0.0, 'c': 0.0}
for key in ('a', 'b', 'c'):
foo[key] = 1.0
mypy currently (0.730) complains about that last line, saying error: TypedDict key must be a string literal; expected one of ('a', 'b', 'c'). It's understandable, but limiting - it'd be great if mypy could recognise that key is in fact one of the valid keys for T.
Aaaaand now I see this juicy-looking patch that went into 0.740, which might be exactly this improvement. Testing now (against my real code, not the hugely simplified case I provided previously)…
Also, +1 on this issue, I think this will be a nice feature.
Reacted by Taro Kuriyama, Ben, Filodamos Papanatsios, Victor Engmark, Dominic , Dries Schaumont, Illviljan, Josefine, Huy Z, Jakub Młokosiewicz and 3 more
Activity
wadetregaskis-linkedin commentedon Nov 4, 2019
Aaaaand now I see this juicy-looking patch that went into 0.740, which might be exactly this improvement. Testing now (against my real code, not the hugely simplified case I provided previously)…
wadetregaskis-linkedin commentedon Nov 5, 2019
Unfortunately, no, mypy 0.740 hasn't addressed this limitation.
ilevkivskyi commentedon Nov 8, 2019
This looks like really low priority.
jamesbraza commentedon Dec 15, 2020
Seems related: #7178
Also, +1 on this issue, I think this will be a nice feature.
97littleleaf11 commentedon Jan 7, 2022
There is a duplicate issue #9230 with more discussion. Let's just close this one!