Author ethan.furman
Recipients barry, eli.bendersky, eric.snow, ethan.furman, ncoghlan, pitrou
Date 2013-09-09.18:58:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1378753130.62.0.150959940535.issue18989@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-09-09 18:58:50ethan.furmansetrecipients: + ethan.furman, barry, ncoghlan, pitrou, eli.bendersky, eric.snow
2013-09-09 18:58:50ethan.furmansetmessageid: <1378753130.62.0.150959940535.issue18989@psf.upfronthosting.co.za>
2013-09-09 18:58:50ethan.furmanlinkissue18989 messages
2013-09-09 18:58:50ethan.furmancreate