pg.typing.Enum¶
Accessible via pg.typing.Enum.
- class Enum(default, values, frozen=False)[source]¶
Bases:
pg.typing.Generic,pg.typing.PrimitiveTypeValue 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:
Returns all acceptable values of this spec.
- format(compact=False, verbose=True, root_indent=0, **kwargs)[source]¶
Format this object.
- Return type:
- noneable(is_noneable=True, use_none_as_default=True)[source]¶
Noneable is specially treated for Enum.
- Return type:
- 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,tuplewhere the container types should have plain Python values as their values.