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
(*[, markdown])Format this object.
noneable
()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.
- 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.