Utilities¶
-
class
properties.utils.
Sentinel
(name, doc)[source]¶ Basic object with name and doc for specifying singletons
Avalable Sentinels:
properties.undefined
- The default value for all Properties if no other default is specified. When an undefined property is accessed, it returns None. Properties that are required must be set to something other than undefined.properties.everything
- Sentinel representing all available properties. This is used when specifying observed properties.
-
properties.
filter_props
(has_props_cls, input_dict, include_immutable=True)[source]¶ Split a dictionary based keys that correspond to Properties
Returns: (props_dict, others_dict) - Tuple of two dictionaries. The first contains key/value pairs from the input dictionary that correspond to the Properties of the input HasProperties class. The second contains the remaining key/value pairs.
Parameters:
- has_props_cls - HasProperties class or instance used to filter the dictionary
- input_dict - Dictionary to filter
- include_immutable - If True (the default), immutable properties (i.e. Properties that inherit from GettableProperty but not Property) are included in props_dict. If False, immutable properties are excluded from props_dict.
For example
class Profile(properties.HasProperties): name = properties.String('First and last name') age = properties.Integer('Age, years') bio_dict = { 'name': 'Bill', 'age': 65, 'hometown': 'Bakersfield', 'email': 'bill@gmail.com', } (props, others) = properties.filter_props(Profile, bio_dict) assert set(props) == {'name', 'age'} assert set(others) == {'hometown', 'email'}
-
class
properties.
ValidationError
(message, reason=None, prop=None, instance=None, _error_tuples=None)[source]¶ Exception type to be raised during property validation
Parameters
- message - Detailed description of the error cause
- reason - Short reason for the error
- prop - Name of property related to the error
- instance - HasProperties instance related to the error
These inputs are stored as a tuple and passed to the
instance._error_hook
method, which may be overridden on the HasProperties class for custom error behavior.