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

Guido van Rossum guido at python.org
Fri Apr 12 18:43:19 CEST 2013


On Fri, Apr 12, 2013 at 9:34 AM, Guido van Rossum <guido at python.org> wrote:
> To me, NotImplementedError means that a subclass didn't implement
> something it should have implemented. But that's not the case here, is
> it? It's not a bug in the class, it's a bug in the call site. So I
> agree it ought to be TypeError.

Seems I was late to this particular argument. :-)

Anyway, as far as I can tell the PEP looks great. I personally think
it would be nicer if regular Enums were ordered (as long as the
underlying values are ordered), but I don't care enough to overrule
the FLUFL.

I do wonder about this passage in the PEP:

> Let's say you wanted to encode an enumeration value in a database.  You might
> want to get the enumeration class object from an enumeration value::
>
>     >>> cls = Colors.red.enum
>     >>> print(cls.__name__)
>     Colors

I don't understand what this has to do with storing enums in a
database. But it reminded me that for the purpose of storing enums in
a database, it would be nice to have two examples: one that stores the
names and looks them up (do you really have to use getattr() for
that?), and one that stores the values and looks them up (how do you
do that at all?).

Should the metaclass-based API used to create IntEnum be documented,
so strongly motivated people can write their own crazy variants?

--
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list