{ } Raw JSON

bundles / traitlets latest / traitlets / traitlets / Dict / __init__

function

traitlets.traitlets:Dict.__init__

source: /traitlets/traitlets.py :3875

Signature

def   __init__ ( self value_trait : TraitType[t.Any, t.Any] | dict[K, V] | Sentinel | None = None per_key_traits : t.Any = None key_trait : TraitType[t.Any, t.Any] | None = None default_value : dict[K, V] | Sentinel | None = traitlets.Undefined ** kwargs : t.Any )  →  None

Summary

Create a dict trait type from a Python dict.

Extended Summary

The default value is created by doing dict(default_value), which creates a copy of the default_value.

Parameters

value_trait : TraitType [ optional ]

The specified trait type to check and use to restrict the values of the dict. If unspecified, values are not checked.

per_key_traits : Dictionary of {keys:trait types} [ optional, keyword-only ]

A Python dictionary containing the types that are valid for restricting the values of the dict on a per-key basis. Each value in this dict should be a Trait for validating

key_trait : TraitType [ optional, keyword-only ]

The type for restricting the keys of the dict. If unspecified, the types of the keys are not checked.

default_value : SequenceType [ optional, keyword-only ]

The default value for the Dict. Must be dict, tuple, or None, and will be cast to a dict if not None. If any key or value traits are specified, the default_value must conform to the constraints.

Examples

a dict whose values must be text
d = Dict(Unicode())
d2['n'] must be an integer d2['s'] must be text
d2 = Dict(per_key_traits={"n": Integer(), "s": Unicode()})
d3's keys must be text d3's values must be integers
d3 = Dict(value_trait=Integer(), key_trait=Unicode())

Aliases

  • traitlets.Dict.__init__