On Apr 22, 2013, at 09:31 AM, Tim Delaney wrote: >I'm fine with iteration order being by sorted name by default, so long as >it's easily overrideable by enum subclasses or metaclasses e.g. an IntEnum >should probably iterate in value order.
It does</timemachine>. :)
>For definition order, a 3.x-only metaclass could be provided:
>
>class Days(enum.Enum, metaclass=enum.DefinitionOrder):
> Monday = 1
> Tuesday = 2
> Wednesday = 3
> Thursday = 4
> Friday = 5
> Saturday = 6
> Sunday = 7
Yep, that's how it works. From flufl.enum:
class IntEnumMetaclass(EnumMetaclass):
# Define an iteration over the integer values instead of the attribute
# names.
def __iter__(cls):
for key in sorted(cls._enums):
yield getattr(cls, cls._enums[key])
IntEnum = IntEnumMetaclass(str('IntEnum'), (Enum,), {
'__doc__': 'A specialized enumeration with values that are also integers.',
'__value_factory__': IntEnumValue,
})
-Barry
signature.asc
Description: PGP signature
_______________________________________________ Python-Dev mailing list [email protected] http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
