Defaults¶
When a HasProperties class is instantiated, default Property values may come from three places. These include, in order of precedence:
_defaultsdictionary on a HasProperties class. This dictionary has Property name/value pairs.Note
Property values specified in
_defaultsare inherited by subclasses unless they are explicitly overwritten in a subclass’s_defaultsdictionary.defaultvalue specified as a keyword argument on thePropertyinstance._class_defaultdefined 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.Listto default to an empty list, you set the default tolistrather 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