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/125839.html below:

[Python-Dev] Enum: subclassing?

[Python-Dev] Enum: subclassing? [Python-Dev] Enum: subclassing?Antoine Pitrou solipsis at pitrou.net
Wed May 1 23:11:16 CEST 2013
On Wed, 1 May 2013 14:04:11 -0700
Eli Bendersky <eliben at gmail.com> wrote:
> 
> You mean this?
> 
> class BehaviorMixin:
>   # bla bla
> 
> class MyBehavingIntEnum(int, BehaviorMixin, Enum):
>   foo = 1
>   bar = 2

Yes, but without the need for multiple inheritance and separate
mixins ;-) Especially if the behaviour is enum-specific, e.g.:

class IETFStatusCode(IntEnum):

    @classmethod
    def from_statusline(cls, line):
        return cls(int(line.split()[0]))

class HTTPStatusCode(IETFStatusCode):
    NOT_FOUND = 404

class SIPStatusCode(IETFStatusCode):
    RINGING = 180


Regards

Antoine.
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