[ty] Add support for properties that return Self (#21335)
## Summary Detect usages of implicit `self` in property getters, which allows us to treat their signature as being generic. closes https://github.com/astral-sh/ty/issues/1502 ## Typing conformance Two new type assertions that are succeeding. ## Ecosystem results Mostly look good. There are a few new false positives related to a bug with constrained typevars that is unrelated to the work here. I reported this as https://github.com/astral-sh/ty/issues/1503. ## Test Plan Added regression tests.
This commit is contained in:
@@ -139,7 +139,7 @@ The first parameter of instance methods always has type `Self`, if it is not exp
|
||||
The name `self` is not special in any way.
|
||||
|
||||
```py
|
||||
def some_decorator(f: Callable) -> Callable:
|
||||
def some_decorator[**P, R](f: Callable[P, R]) -> Callable[P, R]:
|
||||
return f
|
||||
|
||||
class B:
|
||||
@@ -188,10 +188,10 @@ class B:
|
||||
reveal_type(B().name_does_not_matter()) # revealed: B
|
||||
reveal_type(B().positional_only(1)) # revealed: B
|
||||
reveal_type(B().keyword_only(x=1)) # revealed: B
|
||||
# TODO: This should deally be `B`
|
||||
reveal_type(B().decorated_method()) # revealed: Unknown
|
||||
|
||||
# TODO: this should be B
|
||||
reveal_type(B().a_property) # revealed: Unknown
|
||||
reveal_type(B().a_property) # revealed: B
|
||||
|
||||
async def _():
|
||||
reveal_type(await B().async_method()) # revealed: B
|
||||
|
||||
Reference in New Issue
Block a user