FixableTrait

On this page

FixableTrait#

class FixableTrait(trait, default_value=None, unicode=False, range=True, allow_none=True, **kwargs)#

Bases: Union

Fixable parameter, specified in a filename pattern.

A fixable parameter meant to work with filefinder. It can take:

  1. a value of the appropriate type,

  2. a string specifying a range of values, see RangeTrait,

  3. a string that will be interpreted as a regular expression to match a filename part,

  4. 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:
  • trait_types (sequence) – The list of trait types of length at least 1.

  • **kwargs – Extra kwargs passed to TraitType

  • trait (TraitType)

  • default_value (Any)

  • unicode (bool)

  • range (bool)

  • allow_none (bool)

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_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).