<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.32.2">
</HEAD>
<BODY>
On Wed, 2011-07-27 at 19:21 -0700, Guido van Rossum wrote:<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
It's just possible that there's no way to define enums that neither
introduced a new (class) scope nor requires a lot of redundant typing.
I wish I could write
red = Enum(1)
and it made the following true:
assert red == 1
assert isinstance(red, int) # a subclass
assert str(red) == 'red'
But we'd first need a non-hacky way for Enum() to know that it is
being assigned to something named 'red'.
</PRE>
</BLOCKQUOTE>
<BR>
I think the least-hacky way is to live with the redundant typing. <BR>
<BR>
When these objects are passed around, (to/from functions or methods), they will most likely be rebound to more generic names that don't match their string repr anyway.<BR>
<BR>
The label is not directly tied to the name the object is bound to, although it may match at creation time.<BR>
<BR>
<BR>
What name would you give...<BR>
<BR>
colors = []<BR>
colors.append(Enum(1))<BR>
assert str(colors[0]) == ?<BR>
<BR>
<BR>
<BR>
The only other nice alternatives I can think of at the moment requires either special syntax or a new keyword.<BR>
<BR>
red := 1 # same as... red = Enum('red', 1)<BR>
<BR>
enum red, 1 # same as... red = Enum('red', 1)<BR>
<BR>
<BR>
I'd still opt for the more explicit Enum('red', 1) expression first before adding either the syntax or keyword version. Those can come later if it turns out enums are hugely popular.<BR>
<BR>
<BR>
<BR>
The idea of a new class scope for this hurts my head. To many what if's to consider.<BR>
<BR>
Cheers, <BR>
Ron<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
</BODY>
</HTML>