Skip to content

Abstract Properties & Overloaded method has both abstract and non-abstract variants #4165

Closed
@engnadeau

Description

@engnadeau

Expected Behaviour

  • Ability to type check abstract property getters and setters
  • The intention is to have an interface-like design using properties

Actual Behaviour & Repro Case

Python Code

from abc import abstractmethod


class A:
    @property # error occurs here
    @abstractmethod
    def foo(self) -> int:
        pass

    @foo.setter  # type: ignore
    @abstractmethod
    def foo(self, value: int) -> None:
        pass

Mypy CLI

mypy --strict

Result

error: Overloaded method has both abstract and non-abstract variants

Notes

  • The error message is defined here:

    mypy/mypy/messages.py

    Lines 74 to 75 in a1ace48

    INCONSISTENT_ABSTRACT_OVERLOAD = \
    'Overloaded method has both abstract and non-abstract variants'
  • The error is thrown from here:

    mypy/mypy/checker.py

    Lines 329 to 330 in 936ceac

    if num_abstract not in (0, len(defn.items)):
    self.fail(messages.INCONSISTENT_ABSTRACT_OVERLOAD, defn)
  • Removing # type: ignore from @foo.setter causes mypy to throw error: Decorated property not supported, just as in Decorated property not supported #1362

Related Issues

Current Solution

  • Silence the error with @property # type: ignore

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions