Defaults¶
When a HasProperties class is instantiated, default Property values may come from three places. These include, in order of precedence:
_defaults
dictionary on a HasProperties class. This dictionary has Property name/value pairs.Note
Property values specified in
_defaults
are inherited by subclasses unless they are explicitly overwritten in a subclass’s_defaults
dictionary.default
value specified as a keyword argument on theProperty
instance._class_default
defined on the Property class.
Note
Regardless of where the default value is defined, there are several points to note:
- Default values may be callables. In this case
value()
will be used as the default rather thanvalue
. For example, if you want aproperties.List
to default to an empty list, you set the default tolist
rather thanlist()
or[]
, so a new list is created every time. - To eliminate any default value, the default can be set to
properties.undefined
. This is also the fallback _class_default for all Properties if no other default is specified. - Default values are validated in the
HasProperties metaclass