Skip to content

Fix (#20975) subtyping and join for constrained TypeVars#20980

Open
Shrey-N wants to merge 4 commits intopython:masterfrom
Shrey-N:master
Open

Fix (#20975) subtyping and join for constrained TypeVars#20980
Shrey-N wants to merge 4 commits intopython:masterfrom
Shrey-N:master

Conversation

@Shrey-N
Copy link

@Shrey-N Shrey-N commented Mar 6, 2026

This fixes #20975 by refining subtyping and join logic for constrained TypeVars.

Previously, compatible types were flagged as incompatible because it failed to recognize a concrete type as a valid subtype even when it matched every constraint.

Changes:-
Subtyping: Updated subtypes.py to recognize concrete types as valid subtypes when they satisfy all TypeVar constraints.
Join Logic: Modified join.py to ensure the TypeVar is preserved during join operations.

This resolves incorrect arg-type errors where compatible types were being flagged as incompatible in generic contexts.

Closes #20975

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

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 TypeVar with constraints on field initialization

1 participant