Skip to content

Emit diagnostic on unsound call to abstract @classmethod or @staticmethod with trivial body, when accessed on the class object itself #1927

@AlexWaygood

Description

@AlexWaygood

Both pyright and pyrefly detect the unsoundness here, though mypy does not. We should also detect this as unsound and reject it:

from abc import abstractmethod

class F:
    @classmethod
    @abstractmethod
    def method(cls) -> int: ...

# pyright: Method "method" cannot be called because it is abstract and unimplemented  (reportAbstractUsage)
reveal_type(F.method())

Pyright and pyrefly do however allow the classmethod to be called via type[F]. You could argue that this is unsound, since you do not know whether or not you're dealing with a concrete subclass of F or not. But type[] types are generally unsound, and mypy's lint attempting to enforce similar soundness checks for type[] types has proved very unpopular. So I think we should also allow this:

from abc import abstractmethod

class F:
    @classmethod
    @abstractmethod
    def method(cls) -> int: ...

def _(x: type[F]):
    reveal_type(x.method())

Metadata

Metadata

Assignees

Labels

typing semanticstyping-module features, spec compliance, etc

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions