[Python-Dev] constant/enum type in stdlib

Bill Janssen janssen at parc.com
Tue Nov 23 20:26:57 CET 2010


Isaac Morland <ijmorlan at uwaterloo.ca> wrote:

> On Tue, 23 Nov 2010, Antoine Pitrou wrote:
> 
> > Le mardi 23 novembre 2010 à 12:32 -0500, Isaac Morland a écrit :
> >> On Tue, 23 Nov 2010, Antoine Pitrou wrote:
> >>
> >>> We already have a bunch of bizarrely unrelated stuff in collections
> >>> (such as Callable), so we could put enum there too.
> >>
> >> Why not just "enum" (i.e., "from enum import [...]" or "import
> >> enum.[...]")?  Enumerations are one of the basic kinds of types overall
> >> (speaking informally and independent of any specific language) - they
> >> aren't at all exotic.
> >
> > Enumerations aren't a type at all (they have no distinguishing
> > property).

Not in C, but in some other languages.

> Each enumeration is a type (well, OK, not in every language,
> presumably, but certainly in many languages).

The main purpose of that is to be able to catch type mismatches with
static typing, though.  Seems kind of pointless for Python.

> Classes have their own keyword.  I don't think it's disproportionate
> to give enums a top-level module name.

I do.

> Hey, how about this syntax:
> 
> enum Colors:
> 	red = 0
> 	green = 10
> 	blue

Why not

  class Color:
     red = (255, 0, 0)
     green = (0, 255, 0)
     blue = (0, 0, 255)

Seems to handle the situation OK.

Bill


More information about the Python-Dev mailing list