param module¶
A constainer class for arbitrary data, with type and state checking.
Param is the primary class introduces in this file. Empty is a singleton
class denoting an “empty” parameter. The ParameterError class is
also defined here.
- class porchlight.param.Empty¶
Bases:
objectAn empty class representing missing parameters values.
At initialization, if an instance does not already exist it is created. No instance of Empty exists until it has been instantiated once.
It is recommended that
Emptybe used overNoneto denote parameters that have not been initialized with any value, so thatNonecan be treated unambiguously when using porchlight.
- class porchlight.param.Param(name: str, value: ~typing.Any = <porchlight.param.Empty object>, constant: bool = False, restrict: ~typing.Callable | None = None)¶
Bases:
objectContainer class for arbitrary Python data.
Although mutable, editing
Paramobjects directly is strongly discouraged unless absolutely necessary.Paramuses __slots__, and no attributes other than those listed below may be assigned toParamobjects.- _name¶
Parameter name.
- Type:
str
- _value¶
Value of the parameter. If the parameter does not contain an assigned value, this should be
Empty.- Type:
Any
- _type¶
The type corresponding to the type of
Param._value.- Type:
type
- constants¶
True if this object should be considered a constant. If the
Paramvalue is modified byParam.value’s setter, but constant is True, aParameterErrorwill be raised.- Type:
bool
- restrict¶
If a callable, it will be invoked on the parameter whenever the parameter is changed. If it evaluates to False, a
ParameterErroris raised.Example: “temperature” parameter should not be negative or zero in our model:
See
Param.valuefor further details.- Type:
Callable or None
- __init__(name: str, value: ~typing.Any = <porchlight.param.Empty object>, constant: bool = False, restrict: ~typing.Callable | None = None)¶
Initializes the Param object.
- Parameters:
name (
str) – Parameter name.value (
Any) – Value of the parameter. If the parameter does not contain an assigned value, this should be ~porchlight.param.Emptyconstant (
bool) – True if this object should be considered a constant. If theParamvalue is modified by Param.value’s setter, but constant is True, aParameterErrorwill be raised.restrict (
Callableor None) – If a callable is passed, whenever the value property of the parameter is set, restrict will be called on the candidate value. If the result evaluates to False, a ParameterError will be raised.
- exception porchlight.param.ParameterError¶
Bases:
ExceptionError for Param-specific exceptions.