[Python-Dev] Enumeration items: `type(EnumClass.item) is EnumClass` ?

Steven D'Aprano steve at pearwood.info
Mon Apr 29 22:00:57 CEST 2013


On 30/04/13 05:02, MRAB wrote:

>> Why is that backwards? MoreColor is a subclass of Color, so instances
>> of MoreColor are instances of Color, but instances of Color are not
>> instances of MoreColor. That's normal behaviour for subclasses. (All
>> cats are mammals, but not all mammals are cats.)
>>
> Let's say that Color is red, green, or blue.
>
> Let's also say that MoreColor is superset of Color, in other words, any
> of Color, plus cyan, magenta, or yellow.
>
> Red is a Color and a MoreColor (member of Color and MoreColor).
>
> Yellow is a MoreColor, but not a Color (member of MoreColor but not
> Color).
>
> That's the opposite of the rules of inheritance.

Membership != inheritance, you are conflating two independent concepts. I would expect that for membership testing, you should say "value in MoreColor", not isinstance(value, MoreColor).

flufl.enum has been in use for Mailman for many years, and I would like to hear Barry's opinion on this.



-- 
Steven


More information about the Python-Dev mailing list