Is there a way to declare an abstract instance variable for a class in python?
For example, we have an abstract base class, Bird
, with an abstract method fly
implemented using the abc
package, and the abstract instance variable feathers
(what I'm looking for) implemented as a property.
from abc import ABCMeta, abstractmethod
class Bird(metaclass=ABCMeta):
@property
@abstractmethod
def feathers(self):
"""The bird's feathers."""
@abstractmethod
def fly(self):
"""Take flight."""
The problem is that Eagle
, a class derived from Bird
, is required to have feathers
implemented as a property method. So the following is not an acceptable class, but I'd like it to be
class Eagle(Bird):
def __init__(self):
self.feathers = 'quill'
def fly(self):
print('boy are my arms tired')
There might be a problem since the requirement is on the instance itself, and really after its instantiation, so I don't know if things like the abc
package will still work.
Are there some standard ways of handling this?