←back to thread

191 points jwilk | 1 comments | | HN request time: 0.214s | source
Show context
codethief ◴[] No.46230017[source]
Next step: Auto-inferring the correct (most narrow) TypedDict type from a frozendict. (Think `const foo = { … } as const` in TypeScript.) I miss this TS feature in Python on the daily.
replies(5): >>46230085 #>>46230120 #>>46230296 #>>46230354 #>>46230695 #
mrweasel ◴[] No.46230354[source]
What would that do exactly? Auto-generate a TypedDict class?

Bringing up TypedDict is sort of interesting, because it seems like a frozen dictionary could have been implemented by PEP 705, if typing.ReadOnly was enforced at runtime, and not just a hint to a static type checker.

replies(1): >>46230430 #
dmurray ◴[] No.46230430[source]
Auto-generate a TypedDict type while type checking, while doing nothing at runtime.

I expect this is not a very big ask and the various typecheckers will have versions of this soon after release.

replies(2): >>46230566 #>>46232554 #
1. codethief ◴[] No.46232554[source]
After what release? Type checkers already support the various TypedDict PEPs, even those that haven't been accepted yet. Yet, none of them infers TypedDict types.