Skip to content

no error when calling abstract super method with body #5145

Closed

Description

@DetachHead

Describe the Bug

from abc import ABC, abstractmethod


class Foo(ABC):
    @abstractmethod
    def fn(self) -> None:
        raise NotImplementedError

    @abstractmethod
    def fn2(self) -> None: ...


class Bar(Foo):
    def fn(self) -> None:
        super().fn()  # no error

    def fn2(self) -> None:
        super().fn2()  # error

abstractmethods with an implementation should be an error in most cases (see #5143), but either way an error should still be reported when calling one from a base class, especially if its implementation just raises NotImplementedError.

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.w1tkIpUcjk7OwMScBEwiQKMgKTwGFONQDMlZbvn5GkCFwEQEzYQOmDpguSQtD5xDkFIIVBKRsvzySzxBOTU3NQ8YXJA0BrWPoOFGaKYr6OnpYTrYKbFIA-hohIMJuqy4tCC1SENTD6hIU0FBWSEvH5JakB2G3QXYTTGCGAM3g9hUZQJKBAVFqcWpJWAhYOKMwR_TAA

(Only applicable for extension issues) IDE Information

No response

Activity

  1. rchen152 commented on Oct 13, 2026

    @rchen152
    Contributor

    If I understand correctly, the problem is that we report the expected error when the abstract method has body ... but not when it has body raise NotImplementedError?

  2. DetachHead commented on Oct 13, 2026

    @DetachHead
    ContributorAuthor

    yeah. while it is arguably valid for an abstract method to have an implementation (see #5143 and discussion in astral-sh/ty#4693), i think an "implementation" that just raises NotImplementedError should probably just be special-cased to mean the same thing as no implementation.

  3. mvanhorn commented on Oct 13, 2026

    @mvanhorn
    Contributor

    Both body-kind matches now include BodyKind::RaiseNotImplementedError, so an abstract method whose body is only a NotImplementedError raise is treated as unimplemented. super() then reports that the inherited method has no implementation, and a direct call reports that the abstract method cannot be called.

    #5216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions