<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#330033" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 5/5/2013 6:07 AM, Ethan Furman
wrote:<br>
</div>
<blockquote cite="mid:518659AB.6090302@stoneleaf.us" type="cite">class
NEI( NamedInt, Enum ):
<br>
x = NamedInt('the-x', 1 )
<br>
y = NamedInt('the-y', 2 )
<br>
@property
<br>
def __name__(self):
<br>
return self.value.__name__<br>
</blockquote>
<br>
This cured it, thank you. But I really still don't understand why
the numbers showed up as names... seems to me that either the name
of the enumeration member, or the name of the NamedInt should have
showed up, without this property definition.<br>
<br>
The PEP is the only documentation I had, other than the reference
implementation, but I can't say I fully understand the reference
implementation, not having dealt with metaclass much. Hopefully the
documentation will explain all the incantations necessary to make
things work in an expected manner. I guess I don't understand why
Enum can't wrap the __str__ and __repr__ of the type of the mixed
class, instead of replacing it, and then forcing overrides in
subclasses.<br>
<br>
But empirically, it didn't seem to be __str__ and __repr__ that
caused the visible problem, it was __name__. So you asked why would
I want to put a named object as the value of something else with a
name... and that is a fair question... really I don't... but I see
one of the beneficial uses of Enum being collecting flags values
together, and constructing a flag that is useful for debugging (has
a name or expression telling what the values are). So while the PEP
thinks IntEnum is an odd case, I think it is important. And since
IntEnum loses its name when included in an expression, I was trying
to marry it to NamedInt to fill the gap.<br>
<br>
So you asked why would I want to put a named object as the value of
something else with a name... maybe Enum should make provision for
that... if the primary type ( Int for IntEnum, NamedInt for
NamedIntEnum) happens to have a __name__ property, maybe the name of
enumeration members should be passed to the constructor for the
members... in other words,<br>
<br>
class NIE( NamedInt, Enum ):<br>
x = 1<br>
y = 2<br>
<br>
could construct enumeration members x and y whose values are
NamedInt('x', 1) and <br>
NamedInt('y', 2)... <br>
</body>
</html>