pg.typing.Enum

Accessible via pg.typing.Enum.

class Enum(default, values, frozen=False)[source]

Bases: pg.typing.Generic, pg.typing.PrimitiveType

Value spec for enum type.

Examples:

 # A str enum value with options 'a', 'b', 'c' and its default set to 'a'.
 pg.typing.Enum('a', ['a', 'b', 'c'])

 # A mixed-type enum value.
 pg.typing.Enum('a', ['a', 5, True])

 # An optional enum value with default value set to 'a'.
 pg.typing.Enum('a', ['a', 'b', 'c']).noneable()

# A frozen enum with value set to 'a' that is not modifiable by subclasses.
 pg.typing.Enum('a', ['a', 'b', 'c']).freeze('a')

Methods:

format([compact, verbose, root_indent])

Format this object.

is_compatible(other)

Enum specific compatibility check.

noneable([is_noneable, use_none_as_default])

Noneable is specially treated for Enum.

to_json(**kwargs)

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

Attributes:

values

Returns all acceptable values of this spec.

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

Format this object.

Return type:

str

is_compatible(other)[source]

Enum specific compatibility check.

Return type:

bool

noneable(is_noneable=True, use_none_as_default=True)[source]

Noneable is specially treated for Enum.

Return type:

pg.typing.Enum

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:
  • context – JSON conversion context.

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

Returns:

A plain Python value.

property values: List[Any][source]

Returns all acceptable values of this spec.