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

Guido van Rossum guido at python.org
Sun Apr 28 22:02:11 CEST 2013


My opinions added

On Sun, Apr 28, 2013 at 12:32 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> 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.

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

No opinion.

>   - 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.)

>   - should avg_temp be enumerated?

IMO No.

>   - 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

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.

--
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list