Dynamic Property¶
-
class
properties.basic.
DynamicProperty
(doc, func, prop, **kwargs)[source]¶ DynamicProperties are GettableProperties calculated dynamically
These allow for a similar behavior to
@property
with additional documentation and validation built in. DynamicProperties are not saved to the HasProperties instance (and therefore are not serialized), do not fire change notifications, and don’t allow default values.These are created by decorating a single-argument method with a Property instance. This method is registered as the DynamicProperty getter. Setters and deleters may also be registered.
import properties class SpatialInfo(properties.HasProperties): x = properties.Float('x-location') y = properties.Float('y-location') z = properties.Float('z-location') @properties.Vector3('my dynamic vector') def location(self): return [self.x, self.y, self.z] @location.setter def location(self, value): self.x, self.y, self.z = value @location.deleter def location(self): del self.x, self.y, self.z
Note
DynamicProperties should not be directly instantiated; they should be constructed with the above decorator method.
Note
Since DynamicProperties have no saved state, the decorating Property is not allowed to have a
default
value. Also, therequired
attribute will be ignored.Note
When implementing a DynamicProperty getter, care should be taken around when other properties do not yet have a value. In the example above, if
self.x
,self.y
, orself.z
is stillNone
thelocation
vector will be invalid, so callingself.location
will fail. However, if the getter method returnsNone
it will be treated asproperties.undefined
and pass validation.