FixableTrait#
- class FixableTrait(trait, default_value=None, unicode=False, range=True, allow_none=True, **kwargs)#
Bases:
UnionFixable parameter, specified in a filename pattern.
A fixable parameter meant to work with
filefinder. It can take:a value of the appropriate type,
a string specifying a range of values, see
RangeTrait,a string that will be interpreted as a regular expression to match a filename part,
a list of values (see 1), any of which will be accepted as a valid filename part.
- Parameters:
trait (TraitType) – Trait instance.
default_value (Any) – The default value.
unicode (bool) – Allow string values. Default is False as this can be dangerous, any value from command line that cannot be parsed would still be allowed.
range (bool) – If trait is Int or Float, allow to transform a string into a range of value using
RangeTrait.allow_none (bool) – Allow None as a valid value. Default is True.
kwargs – Arguments passed to the Union trait created.
- __init__(trait, default_value=None, unicode=False, range=True, allow_none=True, **kwargs)#
Construct a Union trait.
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:
- Return type:
None
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_pairsin 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).