[ty] Fix false positive for bounded type parameters with NewType by carljm · Pull Request #22542 · astral-sh/ruff (original) (raw)
…king
When calling a method on an instance of a generic class with bounded
type parameters (e.g., C[T: K] where K is a NewType), ty was
incorrectly reporting: "Argument type C[K] does not satisfy upper
bound C[T@C] of type variable Self"
The issue was introduced by PR #22105, which moved the catch-all case
for NewType assignments that falls back to the concrete base type. This
case was placed before the TypeVar handling cases, so when checking K <: T@C (where K is a NewType and T@C is a TypeVar with upper bound K):
- The NewType fallback matched first
- It delegated to
int(K's concrete base type) - Then checked
int <: T@C, which checks ifintsatisfies boundK - But
intis not assignable toK(NewTypes are distinct from their bases)
The fix moves the NewType fallback case after the TypeVar cases, so TypeVar handling takes precedence.
Fixes astral-sh/ty#2467
Multi-file analysis & type inference
label
carljm marked this pull request as ready for review
carljm deleted the claude/fix-issue-2467-NNS0l branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})