Skip to content

Incorrect "implicitly abstract" function when function returns None and implementation is 'pass' #13770

Description

@cmeyer

Bug Report

To Reproduce

import typing

class A(typing.Protocol):
    def require_method(self) -> None: ...

    def optional_method(self) -> None:
        pass

class B(A):
    def require_method(self) -> None:
        print("B")
    
a = B()

Expected Behavior

This is valid code. The optional_method is optional and is implemented with a valid do-nothing body. It doesn't make sense to return None from this function.

Actual Behavior

% mypy --strict file.py
file.py:13: error: Cannot instantiate abstract class "B" with abstract attribute "optional_method"
file.py:13: note: The following method was marked implicitly abstract because it has an empty function body: "optional_method". If it is not meant to be abstract, explicitly return None.
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.981
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10.6

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions