@@ -2283,6 +2283,43 @@ reveal_type(Check.foo()) # N: Revealed type is "def () -> __main__.Check"
2283
2283
reveal_type(Check().foo()) # N: Revealed type is "__main__.Check"
2284
2284
[builtins fixtures/tuple.pyi]
2285
2285
2286
+ [case testSelfInClassmethodWithOtherSelfMethod]
2287
+ from typing import Any, Callable, Self, TypeVar
2288
+
2289
+ _C = TypeVar("_C", bound=Callable[..., Any])
2290
+
2291
+ def identity(func: _C, /) -> _C:
2292
+ return func
2293
+
2294
+ class A:
2295
+ def meth(self) -> Self: ...
2296
+
2297
+ @classmethod
2298
+ def other_meth(cls) -> Self:
2299
+ reveal_type(cls.meth) # N: Revealed type is "def [Self <: __main__.A] (self: Self`1) -> Self`1"
2300
+ reveal_type(A.meth) # N: Revealed type is "def [Self <: __main__.A] (self: Self`2) -> Self`2"
2301
+ return cls().meth()
2302
+
2303
+ class B:
2304
+ @identity
2305
+ def meth(self) -> Self: ...
2306
+
2307
+ @classmethod
2308
+ def other_meth(cls) -> Self:
2309
+ reveal_type(cls.meth) # N: Revealed type is "def [Self <: __main__.B] (self: Self`5) -> Self`5"
2310
+ reveal_type(B.meth) # N: Revealed type is "def [Self <: __main__.B] (self: Self`6) -> Self`6"
2311
+ return cls().meth()
2312
+
2313
+ class C:
2314
+ @classmethod
2315
+ def other_meth(cls) -> Self: ...
2316
+
2317
+ def meth(self) -> Self:
2318
+ reveal_type(self.other_meth) # N: Revealed type is "def () -> Self`0"
2319
+ reveal_type(type(self).other_meth) # N: Revealed type is "def () -> Self`0"
2320
+ return self.other_meth()
2321
+ [builtins fixtures/tuple.pyi]
2322
+
2286
2323
[case testSelfTypeUpperBoundFiler]
2287
2324
from typing import Generic, TypeVar, overload, Sequence
2288
2325
0 commit comments