PEP 354: Enumerations in Python

Terry Hancock hancock at anansispaceworks.com
Wed Mar 1 19:17:51 EST 2006


On Wed, 01 Mar 2006 12:37:26 +1100
Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> Ben Finney <bignose+python at benfinney.id.au> writes:
> > PEP:            354
> > Title:          Enumerations in Python
> > Version:        $Revision: 42186 $
> > Last-Modified:  $Date: 2006-01-26 11:55:20 +1100 (Thu,
> > 26 Jan 2006) $
> 
> Most people seem to be unopposed or in favour of some kind
> of enumeration mechanism making it at least as far as the
> standard library.

... but not to built-ins.  That seems about right to me.

> As I understand it, the current outstanding debates are::
> 
>   * Builtin types versus stdlib module (maybe
>   'collections')
> 
>   * Ordered sequences versus unordered iterables
> 
>   * Immutable versus mutable

I suggest that both are called for, but would have different
names -- the Immutable is the actual "Enum", the mutable is
probably a "Vocabulary" or something else.

>   * Bad comparisons: raise exception versus return
>   NotImplemented

It should raise an error, because client code should use
enumerated values if enumerated values are spec'd in the
API.

>   * Terminology for each of these concepts

+ Tracing of individual "EnumValues" (or "symbols"?) to
  their enum, I should be able to interrogate a value  to
  find what enum it comes from in addition to being  able
  to interrogate an enum to find out what values  belong
  to it.

  Which is more computationally efficient will depend
  on the application, and a single application might
  do better to use each for different tasks, so I think
  it should be reversible.

+ How about documentation of enumerated values? (Where
  does the enum's __doc__ go?). One of the main values
  of using enumerated values is as an aid to documentation,
  but "WED" is still vague.  Could be "Wednesday", could
  be the "Western Education District" or short for
  "Wedding".  Enumerations are most frequently used in
  module APIs, so they are important to document.

  Obviously, the point is so that documentation tools like
  epydoc can capture the enumeration documentation.


-- 
Terry Hancock (hancock at AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com




More information about the Python-list mailing list