pg.typing.Tuple

Accessible via pg.typing.Tuple.

class Tuple(element_values, default=MISSING_VALUE, min_size=None, max_size=None, size=None, transform=None, is_noneable=False, frozen=False)[source]

Bases: pg.typing.Generic, ValueSpecBase

Value spec for tuple type.

Examples:

# A required tuple with 2 items which are non-negative integers.
pg.typing.Tuple([pg.typing.Int(min_value=0), pg.typing.Int(min_value=0)])

# A optional int tuple of size 3 with None as its default value.
pg.typing.Tuple(pg.typing.Int(), size=3).noneable()

# A int tuple with minimal size 1 and maximal size 5.
pg.typing.Tuple(pg.typing.Int(), min_size=1, max_size=5)

# A (int, float) tuple with default value (1, 1.0).
pg.typing.Tuple([pg.typing.Int(), pg.typing.Float()], default=(1, 1.0))

# A frozen tuple that prevents subclass to extend/override.
pg.typing.Tuple(pg.typing.Int()).freeze((1,))

Attributes:

elements

Returns Field specification for tuple elements.

fixed_length

Returns True if current Tuple spec is fixed length.

forward_refs

Returns forward references used in this spec.

max_size

Returns max size of this tuple.

min_size

Returns max size of this tuple.

Methods:

format([compact, verbose, root_indent, ...])

Format this object.

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

property elements: List[Field][source]

Returns Field specification for tuple elements.

property fixed_length: bool[source]

Returns True if current Tuple spec is fixed length.

format(compact=False, verbose=True, root_indent=0, *, markdown=False, hide_default_values=True, hide_missing_values=True, **kwargs)[source]

Format this object.

Return type:

str

property forward_refs: Set[ForwardRef]

Returns forward references used in this spec.

property max_size: int | None[source]

Returns max size of this tuple.

property min_size: int[source]

Returns max size of this tuple.

to_json(**kwargs)[source]

Returns a plain Python value as a representation for this object.

A plain Python value are basic python types that can be serialized into JSON, e.g: bool, int, float, str, dict (with string keys), list, tuple where the container types should have plain Python values as their values.

Return type:

Dict[str, Any]

Parameters:

**kwargs – Keyword arguments as flags to control JSON conversion.

Returns:

A plain Python value.