atom.typed

class atom.typed.Typed(kind, args=None, kwargs=None, factory=None)[source]

Bases: atom.catom.Member

A value which allows objects of a given type or types.

Values will be tested using the PyObject_TypeCheck C API call. This call is equivalent to type(obj) in cls.mro(). It is less flexible but faster than Instance. Use Instance when allowing heterogenous values and Typed when the value type is explicit.

The value of a Typed may be set to None

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

Initialize an Typed.

Parameters :

kind : type

The allowed type 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 factory to use for creating the default value. If this is not provided and ‘args’ and ‘kwargs’ is None, then the default value will be None.

class atom.typed.ForwardTyped(resolve, args=None, kwargs=None, factory=None)[source]

Bases: atom.typed.Typed

A Typed which delays resolving the type definition.

The first time the value is accessed or modified, the type will be resolved and the forward typed will behave identically to a normal typed.

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

Initialize a ForwardTyped.

resolve : callable
A callable which takes no arguments and returns the type to use for validating the values.
args : tuple, optional
If ‘factory’ is None, then ‘resolve’ will return 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 ‘resolve’ will return a callable type and these keywords will be passed to the constructor to create the default value.
factory : callable, optional
An optional factory to use for creating the default value. If this is not provided and ‘args’ and ‘kwargs’ is None, then the default value will be None.
default(owner)[source]

Called to retrieve the default value.

This will resolve and instantiate the type. It will then update the internal default and validate handlers to behave like a normal typed member.

validate(owner, old, new)[source]

Called to validate the value.

This will resolve the type and validate the new value. It will then update the internal default and validate handlers to behave like a normal typed member.

clone()[source]

Create a clone of the ForwardTyped instance.