I'm curious how attrs can be combined with abstract classes. I Want to define an abstract class, that defines abstract properties which every inheriting class must have.
I want use attrs for this inheriting class, to define its properties. So I tried playing a little bit with both:
import abc
import attr
class Parent(object):
__metaclass__ = abc.ABCMeta
@abc.abstractproperty
def x(self):
pass
@attr.s()
class Child(Parent):
x = attr.ib()
c = Child(9)
c.x = 7
raises the following error:
AttributeError: can't set attribute
Perhaps there is a way to declare a property to be abstract using attrs?:
@attr.s()
class Parent(object):
__metaclass__ = abc.ABCMeta
x = attr.ib(abstract=True)
If one finds a better way to gain the benefits of the two modules I'll be very grateful!
Many thanks in advance!