[Python-Dev] Enum: subclassing? (original) (raw)
Steven D'Aprano steve at pearwood.info
Thu May 2 03:47:25 CEST 2013
- Previous message: [Python-Dev] Enum: subclassing?
- Next message: [Python-Dev] Enum: subclassing?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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:
class Directions(Enum): north = 1 east = 2 west = 3 south = 4
class Directions3D(Directions): 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.
-- Steven
- Previous message: [Python-Dev] Enum: subclassing?
- Next message: [Python-Dev] Enum: subclassing?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]