Im asking this because I didn't find any answers that suffice my doubts about Uniform Access Principles in Python, and what is a good practice.
Inside a class, I have the methodology to call or set a property depending on the next cases:
- For getting I use
self.propertysyntax (and notself._property). - For edit, skipping any "check" via the setter, I'll use
self._property = something(for example, for initializing the property in the__init__method). - For edit without skipping the inner logic of the setter, I'll use
self.property = something.
Is this a correct guideline? If not, what is the standard convention? Why and when should a property be accessed through its accessor?
Assume the next class for the question:
class Foo: def __init__(self, something): self._something = something @property def something(self) -> Any: return self._something @something.setter def something(self, any_value): # any validation self._something = any_value