[Python-ideas] constant/enum type in stdlib

Tim Delaney timothy.c.delaney at gmail.com
Wed Feb 13 02:51:14 CET 2013


On 13 February 2013 08:36, Chris Angelico <rosuav at gmail.com> wrote:

> On Tue, Feb 12, 2013 at 7:06 PM, Tim Delaney
> <timothy.c.delaney at gmail.com> wrote:
> > This actually makes a kind of perverse sense. Conceptually the actual
> > EnumValues are the instances of the Enum (and in fact, I've made them
> > pretend to actually be so).
>
> Not so perverse. I think that makes very good sense (but then, I know
> C++ enums, so maybe I'm tainted). Looks good, though I've not actually
> played with the code.
>

And more ...

Firstly, handles more edge cases that might have been mis-identified as
enum values.

EnumParams is now redundant (and will probably be removed), replaced by
calling the (undefined) enum value name.

 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 MyEnum(Enum):
...     A, B
...     C(None, 'c1', c2='2')
...     D(10, 'd')
...     E(None, e='e')
...
>>> repr(MyEnum)
"<enum __main__.MyEnum {<EnumValue 'A': 0>, <EnumValue 'B': 1>, <EnumValue
'C': 2>, <EnumValue 'D': 10>, <EnumValue 'E': 11>}>"
>>> str(MyEnum)
'{A:0, B:1, C:2, D:10, E:11}'
>>> MyEnum.A.args, MyEnum.A.kwargs
((), {})
>>> MyEnum.C.args, MyEnum.C.kwargs
(('c1',), {'c2': '2'})

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


More information about the Python-ideas mailing list