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

bundles / traitlets 5.14.3 / traitlets / traitlets / Union / __init__

function

traitlets.traitlets:Union.__init__

source: /traitlets/traitlets.py :2397

Signature

def   __init__ ( self trait_types : t.Any ** kwargs : t.Any )  →  None

Summary

Construct a Union trait.

Extended Summary

This trait allows values that are allowed by at least one of the specified trait types. A Union traitlet cannot have metadata on its own, besides the metadata of the listed types.

Parameters

trait_types : sequence

The list of trait types of length at least 1.

**kwargs

Extra kwargs passed to TraitType

Notes

Union([Float(), Bool(), Int()]) attempts to validate the provided values with the validation function of Float, then Bool, and finally Int.

Parsing from string is ambiguous for container types which accept other collection-like literals (e.g. List accepting both [] and () precludes Union from ever parsing Union([List(), Tuple()]) as a tuple; you can modify behaviour of too permissive container traits by overriding _literal_from_string_pairs in subclasses. Similarly, parsing unions of numeric types is only unambiguous if types are provided in order of increasing permissiveness, e.g. Union([Int(), Float()]) (since floats accept integer-looking values).

Aliases

  • traitlets.Union.__init__