typing
typing copied to clipboard
Discrepancy between spec and tests on indexing TypedDicts with non-literal variables
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