MCPcopy Create free account
hub / github.com/ipython/traitlets / Tuple

Class Tuple

traitlets/traitlets.py:3728–3854  ·  view source on GitHub ↗

An instance of a Python tuple.

Source from the content-addressed store, hash-verified

3726
3727
3728class Tuple(Container[t.Tuple[t.Any, ...]]):
3729 """An instance of a Python tuple."""
3730
3731 klass = tuple
3732 _cast_types = (list,)
3733
3734 def __init__(self, *traits: t.Any, **kwargs: t.Any) -> None:
3735 """Create a tuple from a list, set, or tuple.
3736
3737 Create a fixed-type tuple with Traits:
3738
3739 ``t = Tuple(Int(), Str(), CStr())``
3740
3741 would be length 3, with Int,Str,CStr for each element.
3742
3743 If only one arg is given and it is not a Trait, it is taken as
3744 default_value:
3745
3746 ``t = Tuple((1, 2, 3))``
3747
3748 Otherwise, ``default_value`` *must* be specified by keyword.
3749
3750 Parameters
3751 ----------
3752 *traits : TraitTypes [ optional ]
3753 the types for restricting the contents of the Tuple. If unspecified,
3754 types are not checked. If specified, then each positional argument
3755 corresponds to an element of the tuple. Tuples defined with traits
3756 are of fixed length.
3757 default_value : SequenceType [ optional ]
3758 The default value for the Tuple. Must be list/tuple/set, and
3759 will be cast to a tuple. If ``traits`` are specified,
3760 ``default_value`` must conform to the shape and type they specify.
3761 **kwargs
3762 Other kwargs passed to `Container`
3763 """
3764 default_value = kwargs.pop("default_value", Undefined)
3765 # allow Tuple((values,)):
3766 if len(traits) == 1 and default_value is Undefined and not is_trait(traits[0]):
3767 default_value = traits[0]
3768 traits = ()
3769
3770 if default_value is None and not kwargs.get("allow_none", False):
3771 # improve backward-compatibility for possible subclasses
3772 # specifying default_value=None as default,
3773 # keeping 'unspecified' behavior (i.e. empty container)
3774 warn(
3775 f"Specifying {self.__class__.__name__}(default_value=None)"
3776 " for no default is deprecated in traitlets 5.0.5."
3777 " Use default_value=Undefined",
3778 DeprecationWarning,
3779 stacklevel=2,
3780 )
3781 default_value = Undefined
3782
3783 if default_value is Undefined:
3784 args: t.Any = ()
3785 elif default_value is None:

Callers 9

CClass · 0.90
TupleTraitClass · 0.90
test_invalid_argsMethod · 0.90
LooseTupleTraitClass · 0.90
test_invalid_argsMethod · 0.90
MultiTupleTraitClass · 0.90
BarClass · 0.90
CSubClass · 0.90

Calls

no outgoing calls

Tested by 3

test_invalid_argsMethod · 0.72
test_invalid_argsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…