[Python-Dev] enum discussion: can someone please summarize open issues?

Ethan Furman ethan at stoneleaf.us
Sun Apr 28 22:36:30 CEST 2013


On 04/28/2013 01:02 PM, Guido van Rossum wrote:
>
> My opinions added

Mine also now added.


>> Example enumeration:
>>
>> class Seasons(Enum):
>>      SPRING = 1
>>      SUMMER = 2
>>      AUTUMN = 3
>>      WINTER = 4
>>
>>      days_in_year = 365
>>
>>      @property
>>      def avg_temp(self):
>>          return (75, 92, 66, 33)[int(self)+1] # enums are 1-based
>>
>>
>> Definite Issues:
>>
>>    - should enum items be of the type of the Enum class? (i.e. type(SPRING)
>> is Seasons)
>
> IMO Yes.

I agree.

>>    - should an enum item be selectable via __call__ instead of __getitem__
>> (i.e. Seasons(3) is AUTUMN)
>
> No opinion.

I think the callable syntax should be supported for database integration and consistency with every (?) other type in 
Python.  No opinion about the __getitem__ portion.


>>    - should days_in_year be enumerated?
>
> Yes. (If you don't want it to be, and it's not a method/descriptor,
> move it out of the class.)

Making it a property to have it in the class certainly works for me.


>>    - should avg_temp be enumerated?
>
> IMO No.

I agree.


>>    - for the above two, how should they be included/excluded?
>
> IMO Everything should be enumerated except
> (a) things with a __get__() method (i.e. descriptors)
> (b) __dunder__ names

This also works for me.


> Also, I believe there's still an issue on the order in which items are
> returned by iter(Seasons), but I don't know which way this is heading.

As somebody pointed out earlier, the only order which cannot be reconstructed after the fact is definition order (value 
order can be, lexical order can be, etc.).  So my vote is to have the default iteration order be the original definition 
order, as any other desired order can be added to the class.

--
~Ethan~


More information about the Python-Dev mailing list