[issue18989] reuse of enum names in class creation inconsistent

Ethan Furman report at bugs.python.org
Fri Sep 13 17:31:12 CEST 2013


Ethan Furman added the comment:

In any other (normal) class, this works:
==================================================================================
-->class Okay:
...   red = 1
...   green = 2
...   blue = 3
...   red = 4
==================================================================================

But not in Enum.

And this works:
==================================================================================
-->class Color:
...   red = 1
...   green = 2
...   blue = 3
...   def red(self):
...     return 42
... 
--> Color.red
<property object at 0x7fee4db306d8>
==================================================================================

This only works in Enum because we added code to deal with it.  If we hadn't, we'd see this:
==================================================================================
<Color.red: <property object at 0x7fee4db30f58>>
==================================================================================

So right now the rule is:  you can overwrite an enum member with anything besides another enum member.  Considering the point of the Enum class is to create enum members this rule is nonsensical as it allows the removal of already created members.

At the very least the rule should be: enum members cannot be overwritten.

I prefer to have the rule: enum members cannot overwrite anything else, and cannot be overwritten by anything else.  This seems to me to be a simpler, more consistent rule, and more in keeping with what an enumeration should be doing.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18989>
_______________________________________


More information about the Python-bugs-list mailing list