Apr-30-2023, 01:58 PM
I'm curious as to the rationale behind the choice of decorator syntax for getters and setters. Take, for example:
It seems to me that the following syntax would have been both more consistent, clearer, and less prone to typos (note that you don't need to specify the property name in both the @property line and def line):
@property def prop(self): return self._prop @prop.setter def prop(self, value): if not isinstance(value, int | float) or value <= 0: raise ValueError("positive number expected") self._prop = value
It seems to me that the following syntax would have been both more consistent, clearer, and less prone to typos (note that you don't need to specify the property name in both the @property line and def line):
@getter def prop(self): return self._prop @setter def prop(self, value): if not isinstance(value, int | float) or value <= 0: raise ValueError("positive number expected") self._prop = value