Python Abstract Attribute
I will only have a single Abstract Class in this particular module and so I'm trying to avoid importing the 'ABC' package. See below for my attempt and the issue I'm running into.
Solution 1:
You're expecting each child class to have self.requirements
right? So change the following code to this.
classEvent(object):
@propertydefrequirements(self):
try:
return self._requirements
except AttributeError:
raise NotImplementedError('subclasses must have requirements')
That way it will return self.requirements. If self.requirements hasn't been implemented by the child class it will raise a not implemented error.
EDIT: Updated return to avoid never-ending loop.
Post a Comment for "Python Abstract Attribute"