A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-May/125864.html below:

[Python-Dev] Enum: subclassing?

[Python-Dev] Enum: subclassing? [Python-Dev] Enum: subclassing?Greg Ewing greg.ewing at canterbury.ac.nz
Thu May 2 05:07:18 CEST 2013
On 02/05/13 13:47, Steven D'Aprano wrote:
> 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

It doesn't necessarily follow that subclassing is the right
mechanism for extending enums, though. If anything, you
really want to "superclass" them. Maybe

   class Directions3D(Enum, extends = Directions):
     up = 5
     down = 6

Then we could have issubclass(Directions, Directions3D)
rather than the reverse.

-- 
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4