I have a class called Node that has an importance and getter installer, 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
Subsequently, I have a Theorem class that inherits from Node . The only difference between Theorem and a Node , in terms of importance , is that a Theorem must have an importance at least 3 .
How can a theorem inherit the importance installer, but add an additional constraint that importance >= 3 ?
I tried to do it as follows:
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
mareoraft
source share