Showing content from http://mail.python.org/pipermail/python-dev/attachments/20130501/45d01aec/attachment.html below:
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#330033" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 4/30/2013 11:08 PM, Barry Warsaw
wrote:<br>
</div>
<blockquote cite="mid:20130430230827.062515ff@anarchist" type="cite">
<pre wrap="">On Apr 28, 2013, at 07:46 PM, Ethan Furman wrote:
</pre>
<blockquote type="cite">
<pre wrap="">and similarly, Enum behavior /should be/ (in my opinion ;)
Season.AUTUMN is Season('AUTUMN') is Season(3)
</pre>
</blockquote>
<pre wrap="">
I think you'll have a problem with this. flufl.enum did this, but it has an
inherent conflict, which is why we removed the getattr-like behavior.
class Things(Enum):
foo = 'bar'
bar = 'foo'
What does Things('foo') return?
Note that it doesn't matter if that's spelled Things['foo'].
Whether it's defined as lookup or instance "creation", you should only map
values to items, and not attribute names to items, and definitely not both.
Let getattr() do attribute name lookup just like normal.
</pre>
</blockquote>
<br>
I agree that it is confusing to be able to index by either the name
of the enum or its value, in the same method. The current
implementation prefers the names, but will check values if the name
is not found, I discovered by experimentation, after reading the
tests. But when there are conflicts (which would be confusing at
best), the inability to look up some enumerations by value, because
the one with that name is found first, would be even more confusing.<br>
<br>
Can Things('foo') lookup by name and Things['foo'] lookup by value?Â
Or does that confuse things too?<br>
</body>
</html>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4