Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,9 +1249,6 @@ def analyze_class_attribute_access(
or isinstance(node.node, Var)
and node.node.is_classmethod
)
is_staticmethod = (is_decorated and cast(Decorator, node.node).func.is_static) or (
isinstance(node.node, SYMBOL_FUNCBASE_TYPES) and node.node.is_static
)
t = get_proper_type(t)
is_trivial_self = False
if isinstance(node.node, Decorator):
Expand All @@ -1274,7 +1271,7 @@ def analyze_class_attribute_access(
original_vars=original_vars,
is_trivial_self=is_trivial_self,
)
if is_decorated and not is_staticmethod:
if is_decorated:
t = expand_self_type_if_needed(
t, mx, cast(Decorator, node.node).var, itype, is_class=is_classmethod
)
Expand Down
37 changes: 37 additions & 0 deletions test-data/unit/check-selftype.test
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,43 @@ reveal_type(Check.foo()) # N: Revealed type is "def () -> __main__.Check"
reveal_type(Check().foo()) # N: Revealed type is "__main__.Check"
[builtins fixtures/tuple.pyi]

[case testSelfInClassmethodWithOtherSelfMethod]
from typing import Any, Callable, Self, TypeVar

_C = TypeVar("_C", bound=Callable[..., Any])

def identity(func: _C, /) -> _C:
return func

class A:
def meth(self) -> Self: ...

@classmethod
def other_meth(cls) -> Self:
reveal_type(cls.meth) # N: Revealed type is "def [Self <: __main__.A] (self: Self`1) -> Self`1"
reveal_type(A.meth) # N: Revealed type is "def [Self <: __main__.A] (self: Self`2) -> Self`2"
return cls().meth()

class B:
@identity
def meth(self) -> Self: ...

@classmethod
def other_meth(cls) -> Self:
reveal_type(cls.meth) # N: Revealed type is "def [Self <: __main__.B] (self: Self`5) -> Self`5"
reveal_type(B.meth) # N: Revealed type is "def [Self <: __main__.B] (self: Self`6) -> Self`6"
return cls().meth()

class C:
@classmethod
def other_meth(cls) -> Self: ...

def meth(self) -> Self:
reveal_type(self.other_meth) # N: Revealed type is "def () -> Self`0"
reveal_type(type(self).other_meth) # N: Revealed type is "def () -> Self`0"
return self.other_meth()
[builtins fixtures/tuple.pyi]

[case testSelfTypeUpperBoundFiler]
from typing import Generic, TypeVar, overload, Sequence

Expand Down
Loading