On Sat, 04 May 2013 06:37:23 -0700 Ethan Furman <et...@stoneleaf.us> wrote: > >>>> > >>>> +1. An enum is basically a bidirectional mapping between some raw > >>>> values and some "nice" instances, so it deserves a well-defined lookup > >>>> operation in each direction. > >> > >> As I see it, there are 3 possible ways forward here: > > > > 4. Offer classmethods named Enum.by_name() and Enum.by_value(). > > Simple and explicit. > > And then you can't have enum items named by_name and by_value.
You can. Normal shadowing rules apply. By the same token, you can't have enum items named __str__ or __init__. How is that a problem? Attribute resolution rules imply some restrictions, which are well-known to all Python programmers. But, really, you can decide on another name if you like: __byname__ or _byname, etc. My point is simply that lookup doesn't *have* to invoke operators, and explicitly named classmethods are less confusing than repurposed operators. Regards Antoine. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com