[Python-Dev] backported Enum (original) (raw)

Barry Warsaw barry at python.org
Fri Jun 28 22:20:27 CEST 2013


On Jun 28, 2013, at 01:07 PM, Jim J. Jewett wrote:

Switching from getitem syntax to call syntax for looking up an enum member by value, e.g.

- return self.enum[value] + return self.enum(value) Interesting that these two were exactly opposite from flufl.enum. Is there a reason why these were reversed?

The individual decisions made (begrudging) sense at the time, although I don't think it was noticed that the combined effect was to switch the meanings.

Call syntax makes sense for converting a value to an enum because that mirrors calling built-in types, e.g. int('7'). Getitem syntax makes sense for lookup-by-name.

Switching from int() to .value to get the integer value of an enum member, e.g.

- return (member.listid, member.address.email, int(member.role)) + return (member.listid, member.address.email, member.role.value) Is just this a style preference?

No. I'm not using IntEnums and regular enums don't have an int, which makes sense because their values can be anything. .value is the way to get at the value. (Note that even though I don't use IntEnums, my values are all integers. It's just not worth it to change all my imports.)

-Barry



More information about the Python-Dev mailing list