Actually, this:
Example for OK:
The second one is fine in my opinion as long as reset() is really needed and used later/elsewhere in the code or as instance method.
def __init__(self): self.variable = 5 @property def variable(self): return self._variable @variable.setter def variable(self, value): self._variable = valueis NOT OK. You don't need to use setter and property in this case. You don't do anything additional in the setter and/or property. In your original code you were checking the value and raising error if not accepted value.
Example for OK:
from math import pi class Circle: def __init__(self, radius): self.radius = radius @property def circumference(self): return 2 * pi * self.radius @property def diameter(self): return self.radius * 2 @diameter.setter def diameter(self, value): self.radius = value / 2 circle = Circle(2) print(f'circumference:{circle.circumference}') print(f'diameter: {circle.diameter}') circle.diameter = 8 print(f'radius: {circle.radius}') print(f'circumference: {circle.circumference}')Note - it's possible to complicate the example by allowing user to define Circle by radius OR diameter in __init__
The second one is fine in my opinion as long as reset() is really needed and used later/elsewhere in the code or as instance method.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs