[Python-Dev] PEP 435: initial values must be specified? Yes
Tim Delaney
timothy.c.delaney at gmail.com
Tue May 7 07:18:41 CEST 2013
More information about the Python-Dev mailing list
Tue May 7 07:18:41 CEST 2013
- Previous message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Next message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 7 May 2013 15:14, Tim Delaney <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: ()> Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130507/9503a9e5/attachment.html>
- Previous message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Next message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list