atom.coerced

class atom.coerced.Coerced(kind, args=None, kwargs=None, factory=None, coercer=None)[source]

Bases: atom.catom.Member

A member which will coerce a value to a given instance type.

Unlike Typed or Instance, a Coerced value is not intended to be set to None.

__init__(kind, args=None, kwargs=None, factory=None, coercer=None)[source]

Initialize a Coerced.

Parameters :

kind : type or tuple of types

The allowable types for the value.

args : tuple, optional

If ‘factory’ is None, then ‘kind’ is a callable type and these arguments will be passed to the constructor to create the default value.

kwargs : dict, optional

If ‘factory’ is None, then ‘kind’ is a callable type and these keywords will be passed to the constructor to create the default value.

factory : callable, optional

An optional callable which takes no arguments and returns the default value for the member. If this is not provided then ‘args’ and ‘kwargs’ should be provided, as ‘kind’ will be used to generate the default value.

coercer : callable, optional

An optional callable which takes the value and returns the coerced value. If this is not given, then ‘kind’ must be a callable type which will be called with the value to coerce the value to the appropriate type.