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.
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}It basically provides data types, but also ensures that you have no easy way to reuse them, and it will miss cases where two data structures happen to have the same signature.
It's getting a little messy when we have class, namedtuple and TypedDict, which all can do much the same thing.
Huh. That's exactly the point: TypedDicts are structural types.
> we have class, namedtuple and TypedDict, which all can do much the same thing.
No, they can't. The former two are nominal types.