Lines Matching refs:Enum
27 sets of names and values: :class:`Enum`, :class:`IntEnum`, :class:`Flag`, and
31 .. class:: Enum
54 Enum class decorator that ensures only one name is bound to any one value.
58 Instances are replaced with an appropriate value for Enum members.
63 Creating an Enum
68 `Functional API`_. To define an enumeration, subclass :class:`Enum` as
71 >>> from enum import Enum
72 >>> class Color(Enum):
78 .. note:: Enum member values
118 Enum members also have a property that contains just their item name::
125 >>> class Shake(Enum):
153 at program-writing time). ``Enum`` allows such access::
181 >>> class Shape(Enum):
194 >>> class Shape(Enum):
227 >>> from enum import Enum, unique
229 ... class Mistake(Enum):
245 >>> from enum import Enum, auto
246 >>> class Color(Enum):
257 >>> class AutoName(Enum):
315 Ordered comparisons between enumeration values are *not* supported. Enum
352 >>> class Mood(Enum):
390 Restricted Enum subclassing
393 A new :class:`Enum` class must have one base Enum class, up to one concrete
412 >>> class Foo(Enum):
446 It is possible to modify how Enum members are pickled/unpickled by defining
453 The :class:`Enum` class is callable, providing the following functional API::
455 >>> Animal = Enum('Animal', 'ANT BEE CAT DOG')
466 argument of the call to :class:`Enum` is the name of the enumeration.
474 new class derived from :class:`Enum` is returned. In other words, the above
477 >>> class Animal(Enum):
494 >>> Animal = Enum('Animal', 'ANT BEE CAT DOG', module=__name__)
498 If ``module`` is not supplied, and Enum cannot determine what it is,
499 the new Enum members will not be unpicklable; to keep errors closer to
507 >>> Animal = Enum('Animal', 'ANT BEE CAT DOG', qualname='SomeData.Animal')
511 …Enum(value='NewEnumName', names=<...>, *, module='...', qualname='...', type=<mixed-in class>, sta…
513 :value: What the new Enum class will record as its name.
515 :names: The Enum members. This can be a whitespace or comma separated string
532 :module: name of module where new Enum class can be found.
534 :qualname: where in module new Enum class can be found.
536 :type: type to mix in to new Enum class.
550 The first variation of :class:`Enum` that is provided is also a subclass of
571 However, they still can't be compared to standard :class:`Enum` enumerations::
577 >>> class Color(Enum):
597 The next variation of :class:`Enum` provided, :class:`IntFlag`, is also based
635 Another important difference between :class:`IntFlag` and :class:`Enum` is that
704 For the majority of new code, :class:`Enum` and :class:`Flag` are strongly
708 and :class:`IntFlag` should be used only in cases where :class:`Enum` and
719 class IntEnum(int, Enum):
727 1. When subclassing :class:`Enum`, mix-in types must appear before
728 :class:`Enum` itself in the sequence of bases, as in the :class:`IntEnum`
730 2. While :class:`Enum` can have members of any type, once you mix in an
738 4. %-style formatting: `%s` and `%r` call the :class:`Enum` class's
743 type's :meth:`__format__`. If the :class:`Enum` class's :func:`str` or
750 While :class:`Enum`, :class:`IntEnum`, :class:`IntFlag`, and :class:`Flag` are
775 >>> class NoValue(Enum):
850 The :meth:`__new__` method, if defined, is used during creation of the Enum
851 members; it is then replaced by Enum's :meth:`__new__` which is used after
859 the normal :class:`Enum` invariants (such as not being comparable to other
862 >>> class OrderedEnum(Enum):
897 >>> class DuplicateFreeEnum(Enum):
919 This is a useful example for subclassing Enum to add or change other
930 >>> class Planet(Enum):
960 >>> class Period(timedelta, Enum):
976 Enums have a custom metaclass that affects many aspects of both derived Enum
980 Enum Classes
985 allow one to do things with an :class:`Enum` class that fail on a typical
987 responsible for ensuring that various other methods on the final :class:`Enum`
992 Enum Members (aka instances)
995 The most interesting thing about Enum members is that they are singletons.
996 :class:`EnumMeta` creates them all while it is creating the :class:`Enum`
1040 >>> class Color(Enum):
1055 ``Enum`` member type
1058 :class:`Enum` members are instances of their :class:`Enum` class, and are
1062 :class:`Enum` member you are looking for (this is another good reason to use
1065 >>> class FieldTypes(Enum):
1078 Boolean value of ``Enum`` classes and members
1081 :class:`Enum` members that are mixed with non-:class:`Enum` types (such as
1084 own Enum's boolean evaluation depend on the member's value add the following to
1090 :class:`Enum` classes always evaluate as :data:`True`.
1093 ``Enum`` classes with methods
1096 If you give your :class:`Enum` subclass extra methods, like the `Planet`_