[Python-Dev] PEP-435 reference implementation
ethan at stoneleaf.us
Wed May 1 07:50:31 CEST 2013
On 04/30/2013 09:47 PM, Barry Warsaw wrote:
> On Apr 30, 2013, at 07:39 PM, Glenn Linderman wrote:
>>>> Because Guido said no subclassing.
>> Indeed, I heard him. But what I heard was that subclasses shouldn't be
>> allowed to define new enumeration values, and that was the point of all his
>> justification and the justifications in the Stack Overflow discussion he
>> linked to. I don't want to disagree, or argue that point, there are reasons
>> for it, although some have raised counter-arguments to it. This is not
>> intended to be a counter-argument to the point that there should be no new
>> enumeration values created in subclasses.
> That's a shame, because disallowing subclassing to extend an enum will break
> my existing use cases. Maybe I won't be able to adopt stdlib.enums after
> all. :(
What is your existing use case?
The way I had subclassing working originally was for the subclass to create it's own versions of the superclass' enum
items -- they weren't the same object, but they were equal:
--> class Color(Enum):
... red = 1
... green = 2
... blue = 3
--> class MoreColor(Color):
... cyan = 4
... magenta = 5
... yellow = 6
--> Color.red is MoreColor.red
--> Color.red == MoreColor.red
If you switched from `is` to `==` would this work for you?
More information about the Python-Dev