Skip to content

Commit 06e28f8

Browse files
Follow-up after #19025: test and cleanup (#19294)
As requested by @ilevkivskyi in #19025 --------- Co-authored-by: Ivan Levkivskyi <[email protected]>
1 parent 5b28b62 commit 06e28f8

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

mypy/checkmember.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,9 +1249,6 @@ def analyze_class_attribute_access(
12491249
or isinstance(node.node, Var)
12501250
and node.node.is_classmethod
12511251
)
1252-
is_staticmethod = (is_decorated and cast(Decorator, node.node).func.is_static) or (
1253-
isinstance(node.node, SYMBOL_FUNCBASE_TYPES) and node.node.is_static
1254-
)
12551252
t = get_proper_type(t)
12561253
is_trivial_self = False
12571254
if isinstance(node.node, Decorator):
@@ -1274,7 +1271,7 @@ def analyze_class_attribute_access(
12741271
original_vars=original_vars,
12751272
is_trivial_self=is_trivial_self,
12761273
)
1277-
if is_decorated and not is_staticmethod:
1274+
if is_decorated:
12781275
t = expand_self_type_if_needed(
12791276
t, mx, cast(Decorator, node.node).var, itype, is_class=is_classmethod
12801277
)

test-data/unit/check-selftype.test

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,43 @@ reveal_type(Check.foo()) # N: Revealed type is "def () -> __main__.Check"
22832283
reveal_type(Check().foo()) # N: Revealed type is "__main__.Check"
22842284
[builtins fixtures/tuple.pyi]
22852285

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+
22862323
[case testSelfTypeUpperBoundFiler]
22872324
from typing import Generic, TypeVar, overload, Sequence
22882325

0 commit comments

Comments
 (0)