atom.instance

class atom.instance.Instance(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_IsInstance C API call. This call is equivalent to isinstance(value, kind) and all the same rules apply.

The value of an Instance may be set to None.

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

Initialize an Instance.

Parameters :

kind : type or tuple of types

The allowed type or types for the instance.

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.instance.ForwardInstance(resolve, args=None, kwargs=None, factory=None)[source]

Bases: atom.instance.Instance

An Instance which delays resolving the type definition.

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

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

Initialize a ForwardInstance.

resolve : callable
A callable which takes no arguments and returns the type or tuple of types 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 instance 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 instance member.

clone()[source]

Create a clone of the ForwardInstance object.