Skip to content

Decorators

Property-recalculation decorators for automatic change propagation.


General

Functions:

recalculate

recalculate(*method_names: str, requires: Optional[Dict[str, Callable]] = None)

Factory that creates a decorator to call self._calculate_<name>() after the wrapped method.

PARAMETER DESCRIPTION
*method_names

One or more method suffixes. For each name, self._calculate_<name>() is called in order after the wrapped function executes.

TYPE: str DEFAULT: ()

requires

Extra attribute guards. Keys are attribute names (e.g. "_mass"), values are callables that receive the attribute value and must return True for the recalculation to proceed. All guards must pass.

TYPE: Optional[Dict[str, Callable]] DEFAULT: None

RETURNS DESCRIPTION

A decorator (usable with @) that wraps a method.

Examples:

>>> calculate_bulk_properties = recalculate("bulk_properties")
>>> calculate_areas = recalculate("coordinates", "areas")
>>> calculate_capacity_curve = recalculate("capacity_curve",
...     requires={"_mass": lambda v: v is not None})

Coordinates

Functions: