Skip to content

Commit 3bbd0d6

Browse files
committed
Add a testcase Ivan asked for
1 parent c528851 commit 3bbd0d6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test-data/unit/check-selftype.test

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,3 +2260,40 @@ class Check:
22602260
reveal_type(Check.foo()) # N: Revealed type is "def () -> __main__.Check"
22612261
reveal_type(Check().foo()) # N: Revealed type is "__main__.Check"
22622262
[builtins fixtures/tuple.pyi]
2263+
2264+
[case testSelfInClassmethodWithOtherSelfMethod]
2265+
from typing import Any, Callable, Self, TypeVar
2266+
2267+
_C = TypeVar("_C", bound=Callable[..., Any])
2268+
2269+
def identity(func: _C, /) -> _C:
2270+
return func
2271+
2272+
class A:
2273+
def meth(self) -> Self: ...
2274+
2275+
@classmethod
2276+
def other_meth(cls) -> Self:
2277+
reveal_type(cls.meth) # N: Revealed type is "def [Self <: __main__.A] (self: Self`1) -> Self`1"
2278+
reveal_type(A.meth) # N: Revealed type is "def [Self <: __main__.A] (self: Self`2) -> Self`2"
2279+
return cls().meth()
2280+
2281+
class B:
2282+
@identity
2283+
def meth(self) -> Self: ...
2284+
2285+
@classmethod
2286+
def other_meth(cls) -> Self:
2287+
reveal_type(cls.meth) # N: Revealed type is "def [Self <: __main__.B] (self: Self`6) -> Self`6"
2288+
reveal_type(B.meth) # N: Revealed type is "def [Self <: __main__.B] (self: Self`7) -> Self`7"
2289+
return cls().meth()
2290+
2291+
class C:
2292+
@classmethod
2293+
def other_meth(cls) -> Self: ...
2294+
2295+
def meth(self) -> Self:
2296+
reveal_type(self.other_meth) # N: Revealed type is "def () -> Self`0"
2297+
reveal_type(type(self).other_meth) # N: Revealed type is "def () -> Self`0"
2298+
return self.other_meth()
2299+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy