On Mon, Mar 15, 2021 at 2:28 PM Guido van Rossum <guido@python.org> wrote:


I think I like your constructor change idea, with a small twist:

     Color(value=<sentinel>, name=<sentinel>, default=<sentinal>)

This would make it possible to search for an enum by value or by name, and also specify a default return value (raising an exception if the default is not set and a member cannot be found).

So specifically this would allow (hope my shorthand is clear):
Color['RED'] --> Color.RED or raises
Color(1) -> Color.RED or raises
Color(1, default=None) -> Color.RED or None
Color(name='RED', default=None) -> Color.RED or None

Additional possibility (just raising it; neither for nor against) with PEP 637:

Color['RED', default=None] --> Color.RED or None


"I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler