-
Couldn't load subscription status.
- Fork 1.6k
[ty] Simplify Self for final types
#21042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
2 | 1 | 0 |
no-matching-overload |
0 | 3 | 0 |
invalid-return-type |
0 | 1 | 0 |
type-assertion-failure |
0 | 1 | 0 |
| Total | 2 | 6 | 0 |
CodSpeed Performance ReportMerging #21042 will degrade performances by 5.41%Comparing Summary
Benchmarks breakdown
Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this some more, I'm not totally sure this is sound for generic methods. Just because an instance type comes from a @final class doesn't mean that there aren't subtypes of that instance type, and the Self type variable could be solved to be one of those subtypes. For example:
import enum
from typing import Self
class F(enum.Enum):
X = 0
Y = 1
def method(self) -> Self:
return self
reveal_type(F.X.method()) # `Literal[F.X]` on `main`, `F` on this branch
Summary
For final classes, we simplify
Selfto an instance of the class.Ideally, we would also do that for other type variables with a final bound, but those seem like a rare edge-case, because there's not really any benefit to using a type variable in the first place, if it's bound to a final type (thank you, @AlexWaygood).
closes astral-sh/ty#1404
Test Plan
Added regression test