[Python-Dev] enum discussion: can someone please summarize open issues?
Glenn Linderman
v+python at g.nevcal.com
Wed May 1 09:19:05 CEST 2013
On 4/30/2013 11:08 PM, Barry Warsaw wrote:
> On Apr 28, 2013, at 07:46 PM, Ethan Furman wrote:
>
>> and similarly, Enum behavior /should be/ (in my opinion ;)
>>
>> Season.AUTUMN is Season('AUTUMN') is Season(3)
> 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.
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.
Can Things('foo') lookup by name and Things['foo'] lookup by value? Or
does that confuse things too?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130501/45d01aec/attachment.html>
More information about the Python-Dev
mailing list