Skip to content

Emit diagnostic on unsound super() call to abstract method with trivial body #1923

@AlexWaygood

Description

@AlexWaygood

Mypy, pyright and pyrefly all detect the unsoundness here. We should too:

from abc import abstractmethod

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

class G(F):
    def method(self) -> int:
        # mypy: error: Call to abstract method "method" of "F" with trivial body via super() is unsafe  [safe-super]
        return super().method()

This is similar to, but distinct from, #1877.

We should ensure that abstract properties are also covered, e.g.

from abc import abstractmethod

class F:
    @property
    @abstractmethod
    def prop(self) -> int: ...

class G(F):
    @property
    def prop(self) -> int:
        # mypy: error: Call to abstract method "method" of "F" with trivial body via super() is unsafe  [safe-super]
        return super().prop

Metadata

Metadata

Assignees

No one assigned

    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