mirror of
https://github.com/astral-sh/ruff
synced 2026-01-09 15:44:22 -05:00
[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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user