python / python/typing

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

Open
#2,053 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: typing spec
Dominant language
Python
Stars
1.8k
Forks
302
Avg merge
23h
Merged PRs (30d)
8

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TypedDict operations spec section and conformance/tests/typeddicts_operations.py around lines 34-38, then read PR 1978 and the linked discussion. Determine whether the conformance tests should reject non-literal indexing or the specification should allow optional enforcement. Done means the spec and conformance tests consistently describe the agreed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, testing
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.