How do you make an abstract property in python?
import abc
class MyClass(abc.ABC):
@abc.abstractmethod
@property
def foo(self):
pass
results in the error AttributeError: attribute '__isabstractmethod__' of 'property' objects is not writable
It turns out that order matters when it comes to python decorators.
@abc.abstractmethod
@property
is not the same as
@property
@abc.abstractmethod
The correct way to create an abstract property is:
import abc
class MyClass(abc.ABC):
@property
@abc.abstractmethod
def foo(self):
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With