[Python-ideas] PEP for enum library type?

Tim Delaney timothy.c.delaney at gmail.com
Tue Feb 12 23:09:04 CET 2013


On 13 February 2013 08:59, Guido van Rossum <guido at python.org> wrote:

> And I'm of the opinion that the most fundamental property of an enum
> is that it doesn't print as an int.


That part is easy.

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from enum import Enum
>>> class Color(Enum):
...     RED
...
>>> str(Color.RED)
'Color.RED'
>>> repr(Color.RED)
"<EnumValue 'Color.RED': 0>"
>>> str(Color)
'{RED:0}'
>>> repr(Color)
"<enum __main__.Color {<EnumValue 'RED': 0>}>"

Making an appropriate str/repr just requires deciding what it should be. I
chose to make the reprs give more information, but there's no reason they
couldn't be simplified.

I'll see if I can come up with a syntax for declaration that we're both
happy with, but I doubt I'll be as happy with it as what I've currently got
(despite its edge cases).

Tim Delaney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130213/76c44a48/attachment.html>


More information about the Python-ideas mailing list