[ty] Infer type of implicit cls parameter in method bodies (#21685)
## Summary Extends https://github.com/astral-sh/ruff/pull/20922 to infer unannotated `cls` parameters as `type[Self]` in method bodies. Part of https://github.com/astral-sh/ty/issues/159.
This commit is contained in:
@@ -63,6 +63,12 @@ python-version = "3.12"
|
||||
from typing import Self
|
||||
|
||||
class A:
|
||||
def __init__(self):
|
||||
reveal_type(self) # revealed: Self@__init__
|
||||
|
||||
def __init_subclass__(cls, default_name, **kwargs):
|
||||
reveal_type(cls) # revealed: type[Self@__init_subclass__]
|
||||
|
||||
def implicit_self(self) -> Self:
|
||||
reveal_type(self) # revealed: Self@implicit_self
|
||||
|
||||
@@ -91,8 +97,7 @@ class A:
|
||||
|
||||
@classmethod
|
||||
def a_classmethod(cls) -> Self:
|
||||
# TODO: This should be type[Self@bar]
|
||||
reveal_type(cls) # revealed: Unknown
|
||||
reveal_type(cls) # revealed: type[Self@a_classmethod]
|
||||
return cls()
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user