bundles / traitlets 5.16.2 / traitlets / traitlets / Union / __init__
function
traitlets.traitlets:Union.__init__
source: /traitlets/traitlets.py:2428
Signature
def __init__(self, trait_types: t.Any, **kwargs: t.Any) → NoneSummary
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: sequenceThe list of trait types of length at least 1.
**kwargsExtra 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__