[Python-Dev] PEP 435: initial values must be specified? Yes (original) (raw)
Tim Delaney timothy.c.delaney at gmail.com
Tue May 7 04:58:42 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 12:29, Ethan Furman <ethan at stoneleaf.us> wrote:
On 05/05/2013 02:55 PM, Tim Delaney wrote:
So long as I can get one of the requirements documented to implement an auto-number syntax I'll be happy enough with stdlib enums I think. class Color(AutoIntEnum): red = ... green = ... blue = ... Will this do? class AutoNumber(Enum): def new(cls): value = len(cls.enuminfo) + 1 obj = object.new(cls) obj.value = value return obj def int(self): return self.value class Color(AutoNumber): red = () green = () blue = ()
Considering that doesn't actually work with the reference implementation (AutoNumber.new is never called) ... no.
print(Color.red._value) print(int(Color.red))
---------- Run Python3 ---------- () Traceback (most recent call last): File "D:\home\repos\mercurial\ref435\ref435.py", line 292, in print(int(Color.red)) TypeError: int returned non-int (type tuple)
Plus I would not want to use the empty tuple for the purpose - at least ... implies something ongoing.
Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130507/eadfbe3e/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 ]