<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/10/2013 11:02 PM, Ethan Furman
wrote:<br>
</div>
<blockquote cite="mid:518DDEED.9050407@stoneleaf.us" type="cite">On
05/10/2013 10:15 PM, Glenn Linderman wrote:
<br>
<blockquote type="cite">
<br>
But the last few lines of demo1 demonstrate that NIE doesn't
like, somehow, remember that its values, deep down under
<br>
the covers, are really int. And doesn't even like them when
they are wrapped into IntET objects. This may or may not
<br>
be a bug in the current Enum implementation.
<br>
</blockquote>
<br>
You're right, sort of. ;)
<br>
<br>
If you do
<br>
<br>
print( repr( NIE1.x.value ))
<br>
<br>
you'll see
<br>
<br>
('NIE1.x', 1)
<br>
<br>
In other words, the value of NEI.x is `('NEI1.x', 1)` and that is
what you would have to pass back into NEI to get the enum member.
<br>
</blockquote>
<br>
Ah! But the value of NIE.x should be IntET('NIE.x', 1), no? So Enum
is presently saving the constructor parameters as the value, rather
than the constructed object? So for Enums of builtin types, there is
little difference, but for complex types (as opposed to complex
numbers), there is a difference, and I guess I ran into the
consequences of that difference.<br>
<br>
<blockquote cite="mid:518DDEED.9050407@stoneleaf.us" type="cite">As
an aside, I suspect you are doing this the hard way. Perhaps
writing your own __new__ in NIE will have better results</blockquote>
<br>
NIE.__new__ wouldn't have the name available, unless it is passed
in. So it seems to me that Enum (or Enum+) has to pass in the
parameter... in which case NIE.__new__ can be pretty ordinary.<br>
<br>
Other implementation strategies that occurred to me... maybe I'll
try them all, if I have time... but time looks to get scarcer
soon...<br>
<br>
* 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.<br>
<br>
* Implement a subclass of Enum that has a bunch of operator tracking
methods like IntET. However, the results of arithmetic operations
couldn't add a new enumeration member (legally), so some other type
would still have to exist... and it would also have to have those
operation tracking methods.<br>
<br>
* Implement a subclass of EnumMeta that installs all the operator
tracking methods. Same legal issue.<br>
<br>
* Do one of the above, but allow new calculated members to exist,
although perhaps not in the initial, iterable set. Might have to
call it something besides Enum to obey the proclamations :)
FlagBits, maybe. But it could use much the same technology as Enum.<br>
<br>
<blockquote type="cite"> (I'd try, but I gotta get some sleep! ;) .
</blockquote>
<br>
Thanks for the response... it cleared up the demo1 mystery, anyway.<br>
<br>
<blockquote cite="mid:518DDEED.9050407@stoneleaf.us" type="cite">Oh,
newest code posted.<br>
</blockquote>
<br>
That'll give me some practice pulling from your repository into mine
:)<br>
</body>
</html>