-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Use C[T] instead of C[Unknown] for the upper bound of Self
#20479
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
Changes from all commits
d76380f
12ce4d6
ff070a5
6b05f13
c400aa7
f7d27ec
948e0e6
3fe9430
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ reveal_type(foo(b"")) # revealed: bytes | |
| ## Methods | ||
|
|
||
| ```py | ||
| from typing import overload | ||
| from typing_extensions import Self, overload | ||
|
|
||
| class Foo1: | ||
| @overload | ||
|
|
@@ -126,6 +126,18 @@ foo2 = Foo2() | |
| reveal_type(foo2.method) # revealed: Overload[() -> None, (x: str) -> str] | ||
| reveal_type(foo2.method()) # revealed: None | ||
| reveal_type(foo2.method("")) # revealed: str | ||
|
|
||
| class Foo3: | ||
| @overload | ||
| def takes_self_or_int(self: Self, x: Self) -> Self: ... | ||
| @overload | ||
| def takes_self_or_int(self: Self, x: int) -> int: ... | ||
| def takes_self_or_int(self: Self, x: Self | int) -> Self | int: | ||
| return x | ||
|
|
||
| foo3 = Foo3() | ||
| reveal_type(foo3.takes_self_or_int(foo3)) # revealed: Foo3 | ||
| reveal_type(foo3.takes_self_or_int(1)) # revealed: int | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a new test case adapted from a The lower of these two assertions was failing with the induct-into-bounds-of-typevars approach, because we would pick the first overload and return |
||
| ``` | ||
|
|
||
| ## Constructor | ||
|
|
||
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.
Why do we need the explicit
Selfannotations in this test?Is this the right way to write the tests long-term (i.e. once we support implicit-type-of-self properly)? If not, should we have a TODO here to remove these annotations?
Uh oh!
There was an error while loading. Please reload this page.
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.
With these explicit
Selfannotations, these all become regression tests for astral-sh/ty#1196. I could have added new tests, but would have had to duplicate the different variance examples from here. Hopefullyselfandself: Selfwill soon be exactly equivalent (?), so yes, we will be able to remove these soon. I added TODO comments.