On Mon, Mar 15, 2021 at 2:28 PM Guido van Rossum <gu...@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 --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/IUSG2AZ6E6VCI7KVC6WQHESQYBJXZLAD/ Code of Conduct: http://python.org/psf/codeofconduct/