[docs] [issue19040] Problems with overriding Enum.__new__

Eli Bendersky report at bugs.python.org
Mon Sep 23 15:57:27 CEST 2013

Eli Bendersky added the comment:

On Sun, Sep 22, 2013 at 9:04 PM, Ethan Furman <report at bugs.python.org>wrote:

> Ethan Furman added the comment:
> Yup, just trying to add some explanation on how it currently works.
> Drekin, I'm sure you've already figured this out, but for those who may
> read this in the future:  what you need is a helper function:
> def OptionalEnum(value):
>     "could also be OptionalEnum(enum, value)"
>     try:
>         return SomeEnum(value) # or return enum(value)
>     except ValueError:
>         return value

Hmm, looks suspiciously similar to _inienum_converter from socket.py ;-)


Python tracker <report at bugs.python.org>

More information about the docs mailing list