pg.typing.List

Accessible via pg.typing.List.

class List(element_value, 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 list type.

Examples:

 # A required non-negative integer list.
 pg.typing.List(pg.typing.Int(min_value=0))

 # A optional str list with 2-5 items.
 pg.typing.List(pg.typing.Str(), min_size=2, max_size=5).noneable()

 # An size-2 list of arbitrary types
 pg.typing.List(pg.typing.Any(), size=2)

# A frozen list that prevents subclass to extend/override.
 pg.typing.List(pg.typing.Int()).freeze([1])

Attributes:

element

Returns Field specification of list element.

forward_refs

Returns forward references used in this spec.

max_size

Returns max size of the list.

min_size

Returns max size of the list.

Methods:

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

Format this object.

to_json(**kwargs)

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

property element: Field[source]

Returns Field specification of list element.

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][source]

Returns forward references used in this spec.

property max_size: int | None[source]

Returns max size of the list.

property min_size: int[source]

Returns max size of the list.

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.