Skip to content

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

Description

@Andrej730

Splitting issue from PR #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.

def func1(variable_key: str):
# > A key that is not a literal should generally be rejected.
movie: Movie = {variable_key: "", "year": 1900} # E: variable key

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions