On 5/5/2013 12:21 AM, Ethan Furman wrote:
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?

:)  It is a stepping stone, but consider it a stupid test case for now.

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`.

Indeed.

But that isn't the problem of biggest concern. I changed NamedInt to use _intname instead of _name, and it didn't cure the bigger problem.

The bigger problem is that the arithmetic on enumeration items, which seems like it should be inherited from NamedInt (and seems to be, because the third value from each print is a NamedInt), doesn't pick up "x" or "y", nor does it pick up "the-x" or "the-y", but rather, it somehow picks up the str of the value.

The third item from each print should be the same in all print statements, but the first, that deals with the NamedInt directly, works, and the others, that are wrapped in Enum, do not.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to