On 05/04/2013 11:31 PM, Glenn Linderman wrote:
x = NamedInt('the-x', 1 )
y = NamedInt('the-y', 2 )
# demonstrate that NamedInt propagates the names into an expression syntax
print( repr( x ), repr( y ), repr( x+y ))
from ref435 import Enum
# requires redundant names, but loses names in the expression
class NEI( NamedInt, Enum ):
x = NamedInt('the-x', 1 )
y = NamedInt('the-y', 2 )
print( repr( NEI( 1 )), repr( NEI( 2 )), repr( NEI(1) + NEI(2)))
Well, my first question would be why are you using named anything in an
enumeration, where it's going to get another name?
But setting that aside, if you
--> print(NEI.x.__name__)
'x'
not 'the-x'.
Now let's look for the clues:
class Enum...
...
@StealthProperty
def name(self):
return self._name
class NamedInt...
...
def __name__(self):
return self._name # look familiar?
When NamedInt goes looking for _name, it finds the one on `x`, not the one on
`x.value`.
--
~Ethan~
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com