On Apr 13, 2013, at 08:37 AM, Tim Delaney wrote: >Just using definition order as the stable iteration order would do the >trick - no need for any comparisons at all. Subclasses (e.g. IntEnum) can >then override it.
I think this isn't possible if we want to keep backward compatibility with earlier Pythons, which I want to do. OTOH, we have another natural sorting order for base Enums sitting right in front of us: the attribute name. These have to be unique and ordered, so why not use this for both the __repr__() and the base Enum __iter__()? IntEnum can override __iter__() to iterate over item values, which also must be ordered. I just made this change to flufl.enum and it seems to work well. >>> from flufl.enum import Enum >>> A = Enum('A', 'a b c') >>> A <A {a: 1, b: 2, c: 3}> >>> for item in A: print(item) ... A.a A.b A.c >>> B = Enum('B', 'c b a') >>> B <B {a: 3, b: 2, c: 1}> >>> for item in B: print(item) ... B.a B.b B.c >>> from flufl.enum import IntEnum >>> C = IntEnum('C', 'c b a') >>> C <C {a: 3, b: 2, c: 1}> >>> for item in C: print(item) ... C.c C.b C.a -Barry _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com