Skip to content

Fix TypedDict tuple context for Collection#21541

Draft
oppnc wants to merge 1 commit into
python:masterfrom
oppnc:fix-typed-dict-collection-context
Draft

Fix TypedDict tuple context for Collection#21541
oppnc wants to merge 1 commit into
python:masterfrom
oppnc:fix-typed-dict-collection-context

Conversation

@oppnc
Copy link
Copy Markdown

@oppnc oppnc commented May 25, 2026

Fixes #8921.

Tuple expressions are contextually typed for Sequence and Iterable, but not for Collection. This meant a tuple literal containing a TypedDict literal could fail when the expected type was Collection[Item], even though the same expression worked for related protocols.

This change adds typing.Collection to the tuple-like contextual typing set and adds regression coverage for both typing.Collection and collections.abc.Collection.

Validation:

  • python -m pytest -n0 -q mypy/test/testcheck.py::TypeCheckSuite::check-typeddict.test

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error with Sequence/Iterable/Collection with tuple of typed dict

1 participant