When a HasProperties class is instantiated, default Property values may come from three places. These include, in order of precedence:

  1. _defaults dictionary on a HasProperties class. This dictionary has Property name/value pairs.


    Property values specified in _defaults are inherited by subclasses unless they are explicitly overwritten in a subclass’s _defaults dictionary.

  2. default value specified as a keyword argument on the Property instance.

  3. _class_default defined on the Property class.


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 than value. For example, if you want a properties.List to default to an empty list, you set the default to list rather than list() 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