@@ -116,7 +116,7 @@ A.implicit_self(1)
116116Passing ` self ` implicitly also verifies the type:
117117
118118``` py
119- from typing import Never
119+ from typing import Never, Callable
120120
121121class Strange :
122122 def can_not_be_called (self : Never) -> None : ...
@@ -139,6 +139,9 @@ The first parameter of instance methods always has type `Self`, if it is not exp
139139The name ` self ` is not special in any way.
140140
141141``` py
142+ def some_decorator (f : Callable) -> Callable:
143+ return f
144+
142145class B :
143146 def name_does_not_matter (this ) -> Self:
144147 reveal_type(this) # revealed: Self@name_does_not_matter
@@ -153,18 +156,45 @@ class B:
153156 reveal_type(self ) # revealed: Self@keyword_only
154157 return self
155158
159+ @some_decorator
160+ def decorated_method (self ) -> Self:
161+ reveal_type(self ) # revealed: Self@decorated_method
162+ return self
163+
156164 @ property
157165 def a_property (self ) -> Self:
158- # TODO : Should reveal Self@a_property
159- reveal_type(self ) # revealed: Unknown
166+ reveal_type(self ) # revealed: Self@a_property
160167 return self
161168
169+ async def async_method (self ) -> Self:
170+ reveal_type(self ) # revealed: Self@async_method
171+ return self
172+
173+ @ staticmethod
174+ def static_method (self ):
175+ # The parameter can be called `self`, but it is not treated as `Self`
176+ reveal_type(self ) # revealed: Unknown
177+
178+ @ staticmethod
179+ @some_decorator
180+ def decorated_static_method (self ):
181+ reveal_type(self ) # revealed: Unknown
182+
183+ @some_decorator
184+ @ staticmethod
185+ def decorated_static_method_2 (self ):
186+ reveal_type(self ) # revealed: Unknown
187+
162188reveal_type(B().name_does_not_matter()) # revealed: B
163189reveal_type(B().positional_only(1 )) # revealed: B
164190reveal_type(B().keyword_only(x = 1 )) # revealed: B
191+ reveal_type(B().decorated_method()) # revealed: Unknown
165192
166193# TODO : this should be B
167194reveal_type(B().a_property) # revealed: Unknown
195+
196+ async def _ ():
197+ reveal_type(await B().async_method()) # revealed: B
168198```
169199
170200This also works for generic classes:
0 commit comments