
On 13 February 2013 08:36, Chris Angelico <rosuav@gmail.com> wrote:
On Tue, Feb 12, 2013 at 7:06 PM, Tim Delaney <timothy.c.delaney@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