[ty] Preserve constrained TypeVar identity in narrowing intersections#23850
Merged
charliermarsh merged 1 commit intomainfrom Mar 10, 2026
Merged
[ty] Preserve constrained TypeVar identity in narrowing intersections#23850charliermarsh merged 1 commit intomainfrom
charliermarsh merged 1 commit intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 85.05%. The percentage of expected errors that received a diagnostic held steady at 78.05%. The number of fully passing files held steady at 63/132. |
|
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
|
charliermarsh
commented
Mar 10, 2026
| def f[T: (P, Q)](t: T) -> None: | ||
| if isinstance(t, P): | ||
| reveal_type(t) # revealed: P | ||
| reveal_type(t) # revealed: T@f & P |
Member
Author
There was a problem hiding this comment.
These look like regressions but I think they might be correct?
Given:
class P:
def p(self) -> None: ...
class Q:
def q(self) -> None: ...
class Both(P, Q):
pass
def f[T: (P, Q)](t: T) -> T:
if isinstance(t, P):
reveal_type(t) # revealed: T@f & P
t.p()
return t
else:
reveal_type(t) # revealed: Q & ~P
t.q()
return t
def takes_q(x: Q) -> Q:
return f(x)
both = Both()
q: Q = takes_q(both) # valid; runtime goes into the `if` branch
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
0 | 40 | 0 |
invalid-assignment |
0 | 24 | 0 |
invalid-return-type |
0 | 17 | 3 |
no-matching-overload |
0 | 7 | 0 |
invalid-argument-type |
2 | 3 | 0 |
possibly-missing-attribute |
0 | 4 | 0 |
| Total | 2 | 95 | 3 |
f349ff1 to
e91cf6c
Compare
Member
Author
|
I understand the spirit of this change but I'm not familiar with the implementation here. The ecosystem diagnostics do look like false positives being removed, though. |
dcreager
approved these changes
Mar 10, 2026
| def f[T: (P, Q)](t: T) -> None: | ||
| if isinstance(t, P): | ||
| reveal_type(t) # revealed: P | ||
| reveal_type(t) # revealed: T@f & P |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes astral-sh/ty#2782.