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

Barry Warsaw barry at python.org
Sat Apr 13 00:23:30 CEST 2013


On Apr 12, 2013, at 12:56 PM, Guido van Rossum wrote:

>Agreed. I can't easily find that in the PEP though. It doesn't mention
>__getitem__ and I can't find any examples of using <enumclass>[<int>].

Indeed, this looks like an omission in the PEP.  flufl.enum's usage
documentation definitely talks about this:

http://pythonhosted.org/flufl.enum/docs/using.html

specifically:

http://pythonhosted.org/flufl.enum/docs/using.html#conversions

Eli, care to add this to the PEP?

>>>Should the metaclass-based API used to create IntEnum be documented,
>>>so strongly motivated people can write their own crazy variants?
>>
>> I think you recommended against that in python-ideas :).
>
>I have changed my mind; I am now at least +0 on documenting the
>metaclass craziness.

It would be fine with me.  I left it out of the flufl.enum docs and we left it
out of the PEP after your original comments, but I'm pretty happy with the API
and can't foresee us changing it (famous last words).

FWIW, we use a special attribute called __value_factory__ on the Enum subclass
to name the class used to create enum values.  This is all there is to
IntEnum:

class IntEnum(Enum):
    """A specialized enumeration with values that are also integers."""
    __value_factory__ = IntEnumValue

and even the IntEnumValue class isn't that big.  It can be even smaller in
Python 3.4 because of the workarounds in flufl.enum for Python 2
compatibility, and deprecations.

Eli, what do you think about documenting the extension API?

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130412/04179c5d/attachment.pgp>


More information about the Python-Dev mailing list