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.
(
self,
trait: t.List[T] | t.Tuple[T] | t.Set[T] | Sentinel | TraitType[T, t.Any] | None = None,
default_value: t.List[T] | t.Tuple[T] | t.Set[T] | Sentinel | None = Undefined,
minlen: int = 0,
maxlen: int = sys.maxsize,
**kwargs: t.Any,
)
| 3592 | _cast_types: t.Any = (tuple,) |
| 3593 | |
| 3594 | def __init__( |
| 3595 | self, |
| 3596 | trait: t.List[T] | t.Tuple[T] | t.Set[T] | Sentinel | TraitType[T, t.Any] | None = None, |
| 3597 | default_value: t.List[T] | t.Tuple[T] | t.Set[T] | Sentinel | None = Undefined, |
| 3598 | minlen: int = 0, |
| 3599 | maxlen: int = sys.maxsize, |
| 3600 | **kwargs: t.Any, |
| 3601 | ) -> None: |
| 3602 | """Create a List trait type from a list, set, or tuple. |
| 3603 | |
| 3604 | The default value is created by doing ``list(default_value)``, |
| 3605 | which creates a copy of the ``default_value``. |
| 3606 | |
| 3607 | ``trait`` can be specified, which restricts the type of elements |
| 3608 | in the container to that TraitType. |
| 3609 | |
| 3610 | If only one arg is given and it is not a Trait, it is taken as |
| 3611 | ``default_value``: |
| 3612 | |
| 3613 | ``c = List([1, 2, 3])`` |
| 3614 | |
| 3615 | Parameters |
| 3616 | ---------- |
| 3617 | trait : TraitType [ optional ] |
| 3618 | the type for restricting the contents of the Container. |
| 3619 | If unspecified, types are not checked. |
| 3620 | default_value : SequenceType [ optional ] |
| 3621 | The default value for the Trait. Must be list/tuple/set, and |
| 3622 | will be cast to the container type. |
| 3623 | minlen : Int [ default 0 ] |
| 3624 | The minimum length of the input list |
| 3625 | maxlen : Int [ default sys.maxsize ] |
| 3626 | The maximum length of the input list |
| 3627 | """ |
| 3628 | self._maxlen = maxlen |
| 3629 | self._minlen = minlen |
| 3630 | super().__init__(trait=trait, default_value=default_value, **kwargs) |
| 3631 | |
| 3632 | def length_error(self, obj: t.Any, value: t.Any) -> None: |
| 3633 | e = ( |