Skip to content

Fix class protocol inference for bounded type variables - #22533

Open
pei711 wants to merge 1 commit into
python:masterfrom
pei711:fix/protocol-typevar-upper-bound
Open

pei711 wants to merge 1 commit into
python:masterfrom
pei711:fix/protocol-typevar-upper-bound

Conversation

@pei711

@pei711 pei711 commented Nov 21, 2026

Copy link
Copy Markdown

When a bounded type variable is passed as type[T] to a class-object protocol, mypy can infer Never even though the type variable's bound satisfies the protocol.

Infer protocol member constraints from the bound class object and add a regression test covering both a concrete class and a bounded type variable. Fixes #22523.

Verified with:

  • runtests.py testProtocolInferenceFromBoundTypeVarClassObject
  • runtests.py check-protocols.test (204 passed, 1 skipped)
  • runtests.py check-generics.test (198 passed, 2 skipped)
  • Black, Ruff, and git diff --check on the changed code

AI assistance was used; I reviewed the code and test results.

@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