<div dir="ltr">On 7 May 2013 12:29, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">On 05/05/2013 02:55 PM, Tim Delaney wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
So long as I can get one of the requirements documented to implement an auto-number syntax I'll be happy enough with<br>
stdlib enums I think.<br>
<br>
class Color(AutoIntEnum):<br>
red = ...<br>
green = ...<br>
blue = ...<br>
<br>
</blockquote>
<br></div>
Will this do?<br>
<br>
class AutoNumber(Enum):<br>
def __new__(cls):<br>
value = len(cls.__enum_info__) + 1<br>
obj = object.__new__(cls)<br>
obj._value = value<br>
return obj<br>
def __int__(self):<br>
return self._value<br>
class Color(AutoNumber):<br>
red = ()<br>
green = ()<br>
blue = ()</blockquote><div><br></div><div style>Considering that doesn't actually work with the reference implementation (AutoNumber.__new__ is never called) ... no.</div><div style><br></div><div style><div>
print(Color.red._value)</div><div>print(int(Color.red))</div><div><br></div></div><div style><div>---------- Run Python3 ----------</div><div>()</div><div>Traceback (most recent call last):</div><div> File "D:\home\repos\mercurial\ref435\ref435.py", line 292, in <module></div>
<div> print(int(Color.red))</div><div>TypeError: __int__ returned non-int (type tuple)</div><div><br></div></div><div style>Plus I would not want to use the empty tuple for the purpose - at least ... implies something ongoing.</div>
<div style><br></div><div style>Tim Delaney</div></div></div></div>