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.list_id, member.address.email, int(member.role)) >> + return (member.list_id, 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 _______________________________________________ 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