I have a class called Node
that has an importance
setter and getter, below:
class Node:
@property
def importance(self):
return self._importance
@importance.setter
def importance(self, new_importance):
if new_importance is not None:
new_importance = check_type_and_clean(new_importance, int)
assert new_importance >= 1 and new_importance <= 10
self._importance = new_importance
Later on, I have a class Theorem
that inherits from Node
. The only difference between a Theorem
and a Node
, as far as importance
is concerned, is that a Theorem
must have an importance
of at least 3
.
How can a Theorem inherit the importance
setter, but add on the additional constraint that importance >= 3
?
I tried to do it this way:
class Theorem(Node):
@importance.setter
def importance(self, new_importance):
self.importance = new_importance # hoping this would use the super() setter
assert self.importance >= 3