robot.utils.setter
¶
setter
¶
Bases: Generic[T, V, A]
Modify instance attributes only when they are set, not when they are get.
Usage::
1 2 3 |
|
The setter method is called when the attribute is assigned like::
1 |
|
and the returned value is stored in the instance in an attribute like
_setter__source
. When the attribute is accessed, the stored value is
returned.
The above example is equivalent to using the standard property
as
follows. The main benefit of using setter
is that it avoids a dummy
getter method::
1 2 3 4 5 6 7 |
|
When using setter
with __slots__
, the special _setter__xxx
attributes needs to be added to __slots__
as well. The provided
:class:SetterAwareType
metaclass can take care of that automatically.