[Python-Dev] PEP 435 - ref impl disc 2 (original) (raw)
Ethan Furman ethan at stoneleaf.us
Tue May 14 04:43:37 CEST 2013
- Previous message: [Python-Dev] PEP 435 - ref impl disc 2
- Next message: [Python-Dev] PEP 435 - ref impl disc 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 import IntET class NIE1( IntET, Enum ): x = 1 y = 2 z = 4 def new(cls, value): member = IntET.new(cls, 'temp', value) member.value = value return member def init(self, value): self.etname = self.name print( repr( NIE1.x.value )) print( repr( NIE1.x + NIE1.y )) print( repr( NIE1.x + ~ NIE1.y)) print( repr( NIE1.x + ~ 2 )) print( repr( NIE1.z * 3 ))
print( repr( NIE1( 1 ) + NIE1(2))) print( repr( NIE1( IntET('NIE1.x', 1 )) + NIE1(2))) --8<-------------------------------------------------------- and my results: 1 IntET('(x + y)', 3) IntET('(x + ~y)', -2) IntET('(x + -3)', -2) IntET('(z * 3)', 12) IntET('(x + y)', 3) IntET('(x + y)', 3)
Forget to mention the good part -- in the custom new you are able to set the value to whatever you want (not a big deal in this case, but if you had several parameters going in you could still make _value be a single, simple int).
--
Ethan
- Previous message: [Python-Dev] PEP 435 - ref impl disc 2
- Next message: [Python-Dev] PEP 435 - ref impl disc 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]