[Python-Dev] PEP 435 - ref impl disc 2

Nick Coghlan ncoghlan at gmail.com
Mon May 6 06:51:33 CEST 2013

On Mon, May 6, 2013 at 12:46 PM, Glenn Linderman <v+python at g.nevcal.com> wrote:
> Sadly, once the Enums are defined, there is to be no way to subclass them to
> add functionality, like producing a NamedInt result from operations on them.

That rule is enforced by the metaclass, so... ;)

Custom metaclasses are amazingly powerful, the trick is to deploy
their power judiciously, such that people can use the custom classes
associated with them without getting confused. SQL Alchemy, Django and
other frameworks do this quite well, but it *does* create subsections
of the type hierarchy which don't play well with others (for example,
having the same class be both an SQL Alchemy Table definition and a
Django Model definition probably isn't going to work).

Enums are the same - they carve out a subtree in the type hierarchy
that *doesn't* behave the same as the standard tree anchored directly
on type. This *is* going to cause conflicts with meta-tools that only
handle ordinary types - the trick is that the cause of the problem (a
custom metaclass) is also the solution (a custom metaclass derived
from enum.enum_type).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list