by codethief · 11mo ago · 0 comments
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.
I expect this is not a very big ask and the various typecheckers will have versions of this soon after release.
class MyType(TypedDict):
a: str
b: int
or infer the type hint in: my_typed_dict: dict[str, int] = {"a": 5}
It should probably be something like: auto_typed: dict[typing.Const, typing.Const] = {"a": 5}
where typing.Const defaults to Any for an empty dict.What I meant was that
foo = {"a": 5}
should be inferred as foo: TypedDict[{ "a": Literal[5] }] = {"a": 5}IMHO TypedDict in Python are essentially broken/useless as is
What is needed is TS style structural matching, like a Protocol for dicts