RangeTrait#

class RangeTrait(*args, **kwargs)#

Bases: List[T]

Allow to specify a list of items using ranges.

The string must match start:stop[:step]. This will generate values between start and stop, spaced by step. The stop value will be included (if step allows it). step is optional and will default to one. The order of start and stop will dictate if values are ascending or descending.

The trait type must be one of allowed_traits (by default float or int).

"2000:2005": [2000, 2001, 2002, 2003, 2004, 2005]
"2000:2005:2": [2000, 2002, 2004]
"2005:2000:2": [2005, 2003, 2001]
"0.:2.:0.5": [0.0, 0.5, 1.0, 1.5, 2.0]
__init__(*args, **kwargs)#

Create a List trait type from a list, set, or tuple.

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

trait can be specified, which restricts the type of elements in the container to that TraitType.

If only one arg is given and it is not a Trait, it is taken as default_value:

c = List([1, 2, 3])

Parameters:
  • trait (TraitType [ optional ]) – the type for restricting the contents of the Container. If unspecified, types are not checked.

  • default_value (SequenceType [ optional ]) – The default value for the Trait. Must be list/tuple/set, and will be cast to the container type.

  • minlen (Int [ default 0 ]) – The minimum length of the input list

  • maxlen (Int [ default sys.maxsize ]) – The maximum length of the input list

Return type:

None

allowed_traits: list[type[TraitType]] = [<class 'traitlets.traitlets.Float'>, <class 'traitlets.traitlets.Int'>]#

Allowed trait types.

from_string(s)#

Get a value from a config string.

Will test for a string specifying a range.

Parameters:

s (str)

Return type:

list[T] | None

from_string_list(s_list)#

Get a value from a config string.

Will test for a string specifying a range.

Parameters:

s_list (list[str])

Return type:

list[T] | None

generate_range(start_s, stop_s, step_s)#

Get a list of value from a range specification.

Parameters:
  • start_s (str) – Strings parameters found in the range specification. Step cannot be ommited here and must be replaced by a default.

  • stop_s (str) – Strings parameters found in the range specification. Step cannot be ommited here and must be replaced by a default.

  • step_s (str) – Strings parameters found in the range specification. Step cannot be ommited here and must be replaced by a default.

Return type:

list[T]