[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

Barry Warsaw barry at python.org
Fri Apr 12 20:56:24 CEST 2013

On Apr 12, 2013, at 04:57 PM, Phil Elson wrote:

>1) Is there limitation that EnumValues themselves must be immutable?

I'm not sure it makes sense to have mutable EnumValues, but yes, they are
immutable in the sense that you cannot change their underlying value (well,
without hackery).

>2) I'm most excited by the prospect of using these Enums as function
>defaults. I've not worked it through fully, but I'm guessing the following
>will work?

Sure, why not? :)

    >>> from flufl.enum import Enum
    >>> X = Enum('X', 'a b c')
    >>> def doit(default=X.b):
    ...   pass
    >>> from inspect import signature
    >>> print(signature(doit))
    (default=<EnumValue: X.b [value=2]>)

>3) Enums are generally used for defining constants - Is there a case to be
>made for using capitals in the 435 as PEP8 suggests, or are enums a special
>case? (http://www.python.org/dev/peps/pep-0008/#constants)

I dunno, I like that the PEP isn't shouting at me. :)

>4) Is there an easy way to create custom EnumValues subclasses? In
>particular it'd be nice to be able to change the __repr__ in some cases to
>hide the value itself, which is often not important.

Yes, although we aren't documenting it so we don't get locked into the API.
If you look at the flufl.enum implementation, you'll see this is how we
implement IntEnums.


More information about the Python-Dev mailing list