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

Eli Bendersky eliben at gmail.com
Sat Apr 13 04:58:20 CEST 2013


On Fri, Apr 12, 2013 at 3:23 PM, Barry Warsaw <barry at python.org> wrote:

> 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?
>
>
Done. getattr did get a mention there, but now I made it more prominent and
described __getitem__ access as well.


>  >>>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?
>

I don't have major objections...

Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130412/07e52a2c/attachment.html>


More information about the Python-Dev mailing list