Message197375
Consider:
==================================================================================
-->from enum import Enum
-->class Color(Enum):
... red = 1
... green = 2
... blue = 3
... red = 4
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in Color
File "/home/ethan/source/python/issue18924/Lib/enum.py", line 87, in __setitem__
raise TypeError('Attempted to reuse key: %r' % key)
TypeError: Attempted to reuse key: 'red'
==================================================================================
versus
==================================================================================
-->class Color(Enum):
... red = 1
... green = 2
... blue = 3
... def red(self):
... return 'fooled ya!'
...
# no error
==================================================================================
or
==================================================================================
-->class Color(Enum):
... red = 1
... green = 2
... blue = 3
... @property
... def red(self):
... return 'fooled ya!'
...
# no error
==================================================================================
In both of the latter two cases the redefinition of 'red' is allowed because the new definition is not an enum member.
This is inconsistent as well as confusing.
I know normal class creation semantics don't place any such limitations on names and allow redefining at will, but Enum is not a regular class. |
|
Date |
User |
Action |
Args |
2013-09-09 18:58:50 | ethan.furman | set | recipients:
+ ethan.furman, barry, ncoghlan, pitrou, eli.bendersky, eric.snow |
2013-09-09 18:58:50 | ethan.furman | set | messageid: <1378753130.62.0.150959940535.issue18989@psf.upfronthosting.co.za> |
2013-09-09 18:58:50 | ethan.furman | link | issue18989 messages |
2013-09-09 18:58:50 | ethan.furman | create | |
|