basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

no error when `abstractmethod` decorator is above `property` decorator

Open DetachHead opened this issue 2 years ago • 1 comments

Describe the problem, ie expected/actual result (if it's not blatantly obvious)

AttributeError: attribute '__isabstractmethod__' of 'property' objects is not writable

Gist to reproduce

from abc import abstractmethod


class Foo:
    @abstractmethod
    @property
    def foo(self) -> int:
        ...

Basedmypy version

No response

Command-line flags

No response

Configuration options from pyproject.toml (and other config files)

No response

Python version used

No response

Operating system and version

No response

DetachHead avatar Aug 19 '23 09:08 DetachHead

So abstractmethod takes a Callable, and in this case we are passing it a property object, which is not callable.

But in reality, all abstractmethod does, is sets an attribute __isabstractmethod__ on the passed object:

def abstractmethod(funcobj):
    funcobj.__isabstractmethod__ = True
    return funcobj

property is a native class whose attributes can't be arbitrarily set.

KotlinIsland avatar Sep 12 '23 07:09 KotlinIsland