Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-21 Thread Glenn Linderman
On 5/20/2013 11:44 PM, Glenn Linderman wrote: On 5/14/2013 7:16 AM, Ethan Furman wrote: Thank you for being persistent. You are correct, the value should be an IntET (at least, with a custom __new__ ;). You know, when you look at something you wrote the night before, and have no idea what yo

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-20 Thread Glenn Linderman
On 5/14/2013 7:16 AM, Ethan Furman wrote: Thank you for being persistent. You are correct, the value should be an IntET (at least, with a custom __new__ ;). You know, when you look at something you wrote the night before, and have no idea what you were trying to say, you know you were tired.

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-14 Thread Ethan Furman
On 05/13/2013 11:11 PM, Ethan Furman wrote: On 05/13/2013 10:01 PM, Glenn Linderman wrote: On 5/13/2013 7:36 PM, Ethan Furman wrote: On 05/10/2013 10:15 PM, Glenn Linderman wrote: So it is quite possible to marry the two, as Ethan helped me figure out using an earlier NamedInt class: class

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-13 Thread Ethan Furman
On 05/13/2013 10:01 PM, Glenn Linderman wrote: On 5/13/2013 7:36 PM, Ethan Furman wrote: On 05/10/2013 10:15 PM, Glenn Linderman wrote: So it is quite possible to marry the two, as Ethan helped me figure out using an earlier NamedInt class: class NIE( IntET, Enum ): x = ('NIE.x', 1)

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-13 Thread Glenn Linderman
On 5/13/2013 7:36 PM, Ethan Furman wrote: On 05/10/2013 10:15 PM, Glenn Linderman wrote: So it is quite possible to marry the two, as Ethan helped me figure out using an earlier NamedInt class: class NIE( IntET, Enum ): x = ('NIE.x', 1) y = ('NIE.y', 2) z = ('NIE.z', 4) and t

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-13 Thread Ethan Furman
On 05/13/2013 07:36 PM, Ethan Furman wrote: Here's your code, revamped. I did make a slight change in the meta -- I moved the name assignment above the __init__ call so it's available in __init__. --8< from ref435 import Enum from flags

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-13 Thread Ethan Furman
On 05/10/2013 10:15 PM, Glenn Linderman wrote: So it is quite possible to marry the two, as Ethan helped me figure out using an earlier NamedInt class: class NIE( IntET, Enum ): x = ('NIE.x', 1) y = ('NIE.y', 2) z = ('NIE.z', 4) and then expressions involving members of NIE (an

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-11 Thread Glenn Linderman
On 5/11/2013 12:11 AM, Glenn Linderman wrote: Oh, newest code posted. That'll give me some practice pulling from your repository into mine :) Well, I had to bring your changes to my local repository, and then push them up to my bitbucket repo... not sure if there is a way to merge from your

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-11 Thread Glenn Linderman
On 5/11/2013 12:11 AM, Glenn Linderman wrote: * I'm playing with adding another keyword parameter to Enum, but it is presently giving me an error about unknown keyword parameter passed to __prepare__ even though I added **kwds to the list of its parameters. I'll learn something by doing this.

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-11 Thread Glenn Linderman
On 5/10/2013 11:02 PM, Ethan Furman wrote: On 05/10/2013 10:15 PM, Glenn Linderman wrote: But the last few lines of demo1 demonstrate that NIE doesn't like, somehow, remember that its values, deep down under the covers, are really int. And doesn't even like them when they are wrapped into In

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-10 Thread Ethan Furman
On 05/10/2013 10:15 PM, Glenn Linderman wrote: But the last few lines of demo1 demonstrate that NIE doesn't like, somehow, remember that its values, deep down under the covers, are really int. And doesn't even like them when they are wrapped into IntET objects. This may or may not be a bug i

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-10 Thread Glenn Linderman
So, thanks everyone for helping me understand the metaclass issues, and helping fix my code and the reference implementation, so that I got a working workaround for enumerations. Twiddling some more newly using hg and bitbucket... learned a lot today... at

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-06 Thread Ethan Furman
On 05/06/2013 08:35 PM, Glenn Linderman wrote: N.B. In your latest ref435.py code, line 105, should be "An Enum class _is_ final..." rather than "in". Thanks, fixed. -- ~Ethan~ ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.o

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-06 Thread Glenn Linderman
On 5/6/2013 6:26 PM, Ethan Furman wrote: On 05/05/2013 01:01 AM, Glenn Linderman wrote: 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

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-06 Thread Ethan Furman
On 05/05/2013 01:01 AM, Glenn Linderman wrote: 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"

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-06 Thread Barry Warsaw
On May 06, 2013, at 02:51 PM, Nick Coghlan wrote: >Enums are the same - they carve out a subtree in the type hierarchy >that *doesn't* behave the same as the standard tree anchored directly >on type. This *is* going to cause conflicts with meta-tools that only >handle ordinary types - the trick is

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Glenn Linderman
On 5/5/2013 9:51 PM, Nick Coghlan wrote: On Mon, May 6, 2013 at 12:46 PM, Glenn Linderman wrote: Sadly, once the Enums are defined, there is to be no way to subclass them to add functionality, like producing a NamedInt result from operations on them. That rule is enforced by the metaclass, so.

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Nick Coghlan
On Mon, May 6, 2013 at 12:46 PM, Glenn Linderman wrote: > Sadly, once the Enums are defined, there is to be no way to subclass them to > add functionality, like producing a NamedInt result from operations on them. That rule is enforced by the metaclass, so... ;) Custom metaclasses are amazingly

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Glenn Linderman
On 5/5/2013 7:14 PM, Nick Coghlan wrote: I think there comes a point where "subclass the metaclass" is the right answer to "how do I do X with this type?". I believe making two different kinds of value labelling mechanisms play nice is such a case :) Could be. Could be that sufficient operator

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Nick Coghlan
On Mon, May 6, 2013 at 8:57 AM, Glenn Linderman wrote: > 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__

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Glenn Linderman
On 5/5/2013 6:07 AM, Ethan Furman wrote: class NEI( NamedInt, Enum ): x = NamedInt('the-x', 1 ) y = NamedInt('the-y', 2 ) @property def __name__(self): return self.value.__name__ This cured it, thank you. But I really still don't understand why the numbers showed up as

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Ethan Furman
On 05/05/2013 01:08 AM, Nick Coghlan wrote: On Sun, May 5, 2013 at 5:21 PM, Ethan Furman wrote: There's also the code in enum_type.__call__ that ensures Enum.__repr__ and Enum.__str__ are used in preference to those from the value type. (Specifically, the code at https://bitbucket.org/stoneleaf

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Ethan Furman
class NEI( NamedInt, Enum ): x = NamedInt('the-x', 1 ) y = NamedInt('the-y', 2 ) @property def __name__(self): return self.value.__name__ ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/p

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Nick Coghlan
On Sun, May 5, 2013 at 5:21 PM, Ethan Furman wrote: > When NamedInt goes looking for _name, it finds the one on `x`, not the one > on `x.value`. There's also the code in enum_type.__call__ that ensures Enum.__repr__ and Enum.__str__ are used in preference to those from the value type. (Specifical

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Glenn Linderman
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 # require

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Ethan Furman
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 exp

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Glenn Linderman
On 5/5/2013 12:10 AM, Glenn Linderman wrote: On 5/4/2013 11:46 PM, Glenn Linderman wrote: Somehow, the overloading is not finding the __add__ operator in the NamedInt class, when the NamedInt's are wrapped in enumerations. And I guess I figured it out... NamedInt needs to test issubclass(

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-05 Thread Glenn Linderman
On 5/4/2013 11:46 PM, Glenn Linderman wrote: Somehow, the overloading is not finding the __add__ operator in the NamedInt class, when the NamedInt's are wrapped in enumerations. And I guess I figured it out... NamedInt needs to test issubclass( type( self ), NamedInt ) rather than is

Re: [Python-Dev] PEP 435 - ref impl disc 2

2013-05-04 Thread Glenn Linderman
On 5/4/2013 11:31 PM, Glenn Linderman wrote: So I have a class based on Nick's Named Values, that has been extended to propagate names into expressions, so that if you have named values 'x' and 'y', when you x + y, the result is a named value whose name is '(x + y)'. Seems pretty awkward t

[Python-Dev] PEP 435 - ref impl disc 2

2013-05-04 Thread Glenn Linderman
So I have a class based on Nick's Named Values, that has been extended to propagate names into expressions, so that if you have named values 'x' and 'y', when you x + y, the result is a named value whose name is '(x + y)'. Seems pretty awkward to integrate this with Enum. Maybe I'm missing