[ty] Support implicit type of cls in signatures (#21771)

## Summary

Extends https://github.com/astral-sh/ruff/pull/20517 to support the
implicit type of `cls` in `@classmethod` signatures. Part of
https://github.com/astral-sh/ty/issues/159.
This commit is contained in:
Ibraheem Ahmed
2025-12-10 16:56:20 -05:00
committed by GitHub
parent 1b44d7e2a7
commit 29bf2cd201
3 changed files with 31 additions and 18 deletions

View File

@@ -607,7 +607,7 @@ class X:
def __init__(self, val: int): ...
def make_another(self) -> Self:
reveal_type(self.__new__) # revealed: def __new__(cls) -> Self@__new__
return self.__new__(X)
return self.__new__(type(self))
```
## Builtin functions and methods

View File

@@ -271,8 +271,7 @@ reveal_type(Person._make) # revealed: bound method <class 'Person'>._make(itera
reveal_type(Person._asdict) # revealed: def _asdict(self) -> dict[str, Any]
reveal_type(Person._replace) # revealed: def _replace(self, **kwargs: Any) -> Self@_replace
# TODO: should be `Person` once we support implicit type of `self`
reveal_type(Person._make(("Alice", 42))) # revealed: Unknown
reveal_type(Person._make(("Alice", 42))) # revealed: Person
person = Person("Alice", 42)