typing icon indicating copy to clipboard operation
typing copied to clipboard

Discrepancy between spec and tests on indexing TypedDicts with non-literal variables

Open Andrej730 opened this issue 6 months ago • 0 comments

Splitting issue from PR https://github.com/python/typing/pull/1978

Spec says that it should be generally rejected (ref)

A key that is not a literal should generally be rejected, since its value is unknown during type checking, and thus can cause some of the above violations.

But currently conformance tests do not reflect it.

https://github.com/python/typing/blob/2d88da2a407b556f5b52b4c6ad1bd659873bb9ac/conformance/tests/typeddicts_operations.py#L34-L38

So in theory to resolve this, either strictness should be reflected in conformance tests or spec should be amended allowing optional enforcement.

Related discussion - https://discuss.python.org/t/indexing-typeddict-with-a-non-literal-variable/88929

Andrej730 avatar Jul 21 '25 19:07 Andrej730