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]

    def location(self, value):
        self.x, self.y, self.z = value

    def location(self):
        del self.x, self.y, self.z


DynamicProperties should not be directly instantiated; they should be constructed with the above decorator method.


Since DynamicProperties have no saved state, the decorating Property is not allowed to have a default value. Also, the required attribute will be ignored.


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, or self.z is still None the location vector will be invalid, so calling self.location will fail. However, if the getter method returns None it will be treated as properties.undefined and pass validation.


Register a delete function for the DynamicProperty

This function may only take one argument, self.


Register a set function for the DynamicProperty

This function must take two arguments, self and the new value. Input value to the function is validated with prop validation prior to execution.