<div dir="ltr">On 21 April 2013 21:02, Greg Ewing <span dir="ltr"><<a href="mailto:greg.ewing@canterbury.ac.nz" target="_blank">greg.ewing@canterbury.ac.nz</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Barry Warsaw wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Apr 13, 2013, at 12:51 PM, Steven D'Aprano wrote:<br>
</blockquote>
<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

class Insect(Enum):<br>
   wasp = wsap = 1<br>
   bee = 2<br>
   ant = 3<br>
<br>
What's the justification for this restriction? I have looked in the PEP, and<br>
didn't see one.<br>
</blockquote>
<br>
If you allowed this, there would be no way to look up an enumeration item by<br>
value.  This is necessary for e.g. storing the value in a database.<br>
</blockquote>
<br></div>
Hm. What you really want there isn't two enum objects with<br>
the same value, but two names bound to the same enum object.<br>
Then looking it up by value would not be a problem.</blockquote><div><br></div><div style>If there were some way to identify the canonical name a lookup by value would be unambiguous. If we have iteration in definition order, I'd say the first defined name for a value should be the canonical name, and any other name for the value should be considered an alias.</div>
<div style><br></div><div style>That would preclude the syntax above, but the following might be workable:</div><div style><br></div><div style>class Insect(Enum):</div><div style>    wasp = 1</div><div style>    bee = 2</div>
<div style>    ant = 3</div><div style><br></div><div style>    # aliases</div><div style>    wsap = wasp</div><div style>    waps = 1</div><div style><br></div><div style>In the above, looking up by the value 1 would always return Insect.wasp.</div>
<div style><br></div><div style>Tim Delaney <br></div></div></div></div>