Dynamic Property¶
-
class
properties.basic.DynamicProperty(doc, func, prop, **kwargs)[source]¶ DynamicProperties are GettableProperties calculated dynamically
These allow for a similar behavior to
@propertywith 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
defaultvalue. Also, therequiredattribute 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.zis stillNonethelocationvector will be invalid, so callingself.locationwill fail. However, if the getter method returnsNoneit will be treated asproperties.undefinedand pass validation.