Create a Set trait type from a list, set, or tuple. The default value is created by doing ``set(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.Any = None,
default_value: t.Any = Undefined,
minlen: int = 0,
maxlen: int = sys.maxsize,
**kwargs: t.Any,
)
| 3660 | |
| 3661 | # Redefine __init__ just to make the docstring more accurate. |
| 3662 | def __init__( |
| 3663 | self, |
| 3664 | trait: t.Any = None, |
| 3665 | default_value: t.Any = Undefined, |
| 3666 | minlen: int = 0, |
| 3667 | maxlen: int = sys.maxsize, |
| 3668 | **kwargs: t.Any, |
| 3669 | ) -> None: |
| 3670 | """Create a Set trait type from a list, set, or tuple. |
| 3671 | |
| 3672 | The default value is created by doing ``set(default_value)``, |
| 3673 | which creates a copy of the ``default_value``. |
| 3674 | |
| 3675 | ``trait`` can be specified, which restricts the type of elements |
| 3676 | in the container to that TraitType. |
| 3677 | |
| 3678 | If only one arg is given and it is not a Trait, it is taken as |
| 3679 | ``default_value``: |
| 3680 | |
| 3681 | ``c = Set({1, 2, 3})`` |
| 3682 | |
| 3683 | Parameters |
| 3684 | ---------- |
| 3685 | trait : TraitType [ optional ] |
| 3686 | the type for restricting the contents of the Container. |
| 3687 | If unspecified, types are not checked. |
| 3688 | default_value : SequenceType [ optional ] |
| 3689 | The default value for the Trait. Must be list/tuple/set, and |
| 3690 | will be cast to the container type. |
| 3691 | minlen : Int [ default 0 ] |
| 3692 | The minimum length of the input list |
| 3693 | maxlen : Int [ default sys.maxsize ] |
| 3694 | The maximum length of the input list |
| 3695 | """ |
| 3696 | self._maxlen = maxlen |
| 3697 | self._minlen = minlen |
| 3698 | super().__init__(trait=trait, default_value=default_value, **kwargs) |
| 3699 | |
| 3700 | def length_error(self, obj: t.Any, value: t.Any) -> None: |
| 3701 | e = ( |