PEP 354: Enumerations in Python
Kay Schluehr
kay.schluehr at gmx.net
Mon Feb 27 00:46:54 EST 2006
Ben Finney wrote:
> Metaclass for creating enumeration classes
> ------------------------------------------
>
> The enumerations specified in this PEP are instances of an ``enum``
> type. Some alternative designs implement each enumeration as its own
> class, and a metaclass to define common properties of all
> enumerations.
>
> One motivation for having a class (rather than an instance) for each
> enumeration is to allow subclasses of enumerations, extending and
> altering an existing enumeration. A class, though, implies that
> instances of that class will be created; it is difficult to imagine
> what it means to have separate instances of a "days of the week"
> class, where each instance contains all days. This usually leads to
> having each class follow the Singleton pattern, further complicating
> the design.
>
> In contrast, this PEP specifies enumerations that are not expected to
> be extended or modified. It is, of course, possible to create a new
> enumeration from the string values of an existing one, or even
> subclass the ``enum`` type if desired.
Maybe a metaclass implementation complicates design, but usage is quite
simple and flexible. The classics is already referenced by the Python
docs:
http://www.python.org/doc/essays/metaclasses/Enum.py
I'm -0 on the PEP.
Kay
More information about the Python-list
mailing list