[Python-Dev] Enum: subclassing?
steve at pearwood.info
Thu May 2 03:47:25 CEST 2013
On 02/05/13 06:45, Antoine Pitrou wrote:
> I was talking in the context where subclassing is allowed. I don't
> think there's a use-case for subclassing of non-empty enums. On the
> other hand, empty enums should probably allow subclassing (they are
> "abstract base enums", in a way).
If you google for "subclassing enums" you will find many people asking
how to subclass enums.
Apparently Apache's Java allows subclassing, if I'm reading this correctly:
So do Scala and Kotlin.
The most obvious use-case for subclassing enums is to extend them:
north = 1
east = 2
west = 3
south = 4
up = 5
down = 6
If you allow enums to have methods, then the most obvious use-case is to add or extend methods, no different to any other class.
More information about the Python-Dev