You are viewing an older version (5.14.3). Go to latest (5.15.0)
{ } Raw JSON

bundles / traitlets 5.14.3 / traitlets / traitlets / Instance / __init__

function

traitlets.traitlets:Instance.__init__

source: /traitlets/traitlets.py :2248

Signature

def   __init__ ( self klass : str | type[T] | None = None args : tuple[t.Any, ...] | None = None kw : dict[str, t.Any] | None = None allow_none : bool = False read_only : bool | None = None help : str | None = None ** kwargs : t.Any )  →  None

Summary

Construct an Instance trait.

Extended Summary

This trait allows values that are instances of a particular class or its subclasses. Our implementation is quite different from that of enthough.traits as we don't allow instances to be used for klass and we handle the args and kw arguments differently.

Parameters

klass : class, str

The class that forms the basis for the trait. Class names can also be specified as strings, like 'foo.bar.Bar'.

args : tuple

Positional arguments for generating the default value.

kw : dict

Keyword arguments for generating the default value.

allow_none : bool [ default False ]

Indicates whether None is allowed as a value.

**kwargs

Extra kwargs passed to ClassBasedTraitType

Notes

If both args and kw are None, then the default value is None. If args is a tuple and kw is a dict, then the default is created as klass(*args, **kw). If exactly one of args or kw is None, the None is replaced by () or {}, respectively.

Aliases

  • traitlets.Instance.__init__