[Python-Dev] PEP 435: initial values must be specified? Yes

Ethan Furman ethan at stoneleaf.us
Tue May 7 11:49:47 CEST 2013


On 05/06/2013 10:18 PM, Tim Delaney wrote:
> On 7 May 2013 15:14, Tim Delaney <timothy.c.delaney at gmail.com <mailto:timothy.c.delaney at gmail.com>> wrote:
>
>     Unfortunately, if you subclass AutoNumber from IntEnum it breaks.
>
>     ---------- Run Python3 ----------
>     Traceback (most recent call last):
>        File "D:\home\repos\mercurial\ref435\ref435.py", line 346, in <module>
>          class Color(AutoNumber):
>        File "D:\home\repos\mercurial\ref435\ref435.py", line 184, in __new__
>          enum_item = __new__(enum_class, *args)
>     TypeError: int() argument must be a string or a number, not 'ellipsis'
>
>
> Or using your exact implementation, but subclassing AutoNumber from IntEnum:
>
>      class AutoNumber(IntEnum):
>          def __new__(cls):
>              value = len(cls.__enum_info__) + 1
>              obj = object.__new__(cls)
>              obj._value = value
>              return obj
>          def __int__(self):
>              return self._value
>      class Color(AutoNumber):
>          red = ()
>          green = ()
>          blue = ()
>
>      print(repr(Color.red))
>
> ---------- Run Python3 ----------
> <Color.red: ()>

Thanks for the test case.  It now passes.

--
~Ethan~


More information about the Python-Dev mailing list