[ty] allow any string Literal type expression as a key when constructing a TypedDict by mtshiba · Pull Request #20792 · astral-sh/ruff (original) (raw)
Summary
This PR allows any string Literal type expression to be used as a key when constructing a TypedDict.
The pattern of reusing constant key strings when constructing a TypedDict seems to be common in several libraries (e.g., home-assistant/core).
Currently, we only accept string literal keys when constructing a TypedDict, but any expression that can be inferred to be of type string Literal is also acceptable. In fact, the spec explicitly states that Literal type expressions and Final names should be allowed.
Test Plan
New tests in typed_dict.md