[Python-Dev] [Python-checkins] peps: Pre-alpha draft for PEP 435 (enum). The name is not important at the moment, as

Stephen J. Turnbull stephen at xemacs.org
Tue Feb 26 10:29:00 CET 2013


Ethan Furman writes:
>>>>> sjt wrote:

 > > Note that in both counting and listing the object of the
 > > operation is not an element.  It is a set, and set membership is
 > > the most important aspect of the elements for that purpose.
 > 
 > No, it isn't.  It may be in some cases.

I'm referring only to the dictionary definitions you quote.

It really sounds to me like your use case (and even more so,
Antoine's) would be perfectly well-served by a named constant class
that doesn't know anything about enumerability.

 > My enums even respect it to the point of not comparing equal to
 > different enum sets.  But, quite frankly, it's the enum's ability
 > to let me use a name to mean a number that is the most
 > important. And the most important thing for the Enum class is to
 > assign those numbers for me as automatically as possible.

But "mean a number" and "assigned automatically" are close to mutually
exclusive (except that "as possible" gives you a lot of wiggle room).

That is, if by "name means number" you imply that the numbers have
semantics (as in Antoine's HTTP status code example), you care what
the numbers are, and they can't be assigned automatically.

OTOH, if the numbers are assigned very automatically (ie, completely
implicitly), I have trouble with coming up with a use case where
ability to use integer arithmetic (including comparisons other than
equality and set membership) on them *by default* is anything but a
trap.  Eg, with a Likert scale for preference[1], I *do* want to order
them, but (at least when I'm teaching statistics) I *really* *don't*
want them added and subtracted without thinking about exactly what the
operation means.

And if you really need arithmetic and automatic assignment is good
enough, what's wrong with their ordinary names (ie, 1, 2, 3, ...)?
<wink/>

Footnotes: 
[1]  A qualitative expression of strength of feeling ("hate" = 1,
"dislike" = 2, "indifferent" = 3, "like" = 4, "love" = 5).


More information about the Python-Dev mailing list