Skip to content

Fix inference for bounded type object protocols - #22532

Open
pei711 wants to merge 1 commit into
python:masterfrom
pei711:fix/bounded-type-protocol-inference
Open

pei711 wants to merge 1 commit into
python:masterfrom
pei711:fix/bounded-type-protocol-inference

Conversation

@pei711

@pei711 pei711 commented Nov 21, 2026

Copy link
Copy Markdown

Fixes #22523

When a generic function receives type[T] and T is bounded by a class that implements a protocol, mypy previously skipped the bound class's protocol members during inference. This left the protocol type argument as Never, even though the same call worked with the concrete class type.

Normalize a type variable to its upper bound before inferring class-object protocol members. Add a regression test covering the reported ClassVar case.

Verified with:

  • Protocol unit tests: 204 passed, 1 skipped.
  • Generic and type variable default unit tests: 235 passed, 2 skipped.
  • Black and Ruff checks for mypy/constraints.py.
  • EOF and trailing-whitespace checks for both changed files.

@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.

Protocol type argument inference fails for bounded type[T]

1 participant