This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Robert Gomułka
Recipients Robert Gomułka
Date 2017-09-26.06:58:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1506409097.06.0.130027290972.issue31587@psf.upfronthosting.co.za>
In-reply-to
Content
Enum module handles "name" member incorrectly.
1. "name" can't be used as a member when decorated with unique:

>>> import enum
>>> @enum.unique
... class A(enum.IntEnum):
...     a = 1
...     name = 2
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Python27\Lib\site-packages\enum\__init__.py", line 835, in unique
    (enumeration, duplicate_names)
ValueError: duplicate names found in <enum 'A'>: a -> A.name, name -> A.name

2. Without unique the names are assigned incorrectly:

>>> class A(enum.IntEnum):
...     a = 1
...     name = 2
...
>>> A.__members__['a'].name
<A.name: 2>
>>> A.__members__['name'].name
<A.name: 2>

(Just for reference - spotted first on Python 2.7 + enum34 backports)

The same happens for value property, making the bug quite severe:

>>> class A(enum.IntEnum):
...     a = 1
...     value = 3
...
>>> A.__members__['a'].value
<A.value: 3>
>>> A.__members__['value'].value
<A.value: 3>

I believe this comment is related:
# _RouteClassAttributeToGetattr is used to provide access to the `name`
# and `value` properties of enum members while keeping some measure of
# protection from modification, while still allowing for an enumeration
# to have members named `name` and `value`.  This works because enumeration
# members are not set directly on the enum class -- __getattr__ is
# used to look them up.


Platform: Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
History
Date User Action Args
2017-09-26 06:58:17Robert Gomułkasetrecipients: + Robert Gomułka
2017-09-26 06:58:17Robert Gomułkasetmessageid: <1506409097.06.0.130027290972.issue31587@psf.upfronthosting.co.za>
2017-09-26 06:58:17Robert Gomułkalinkissue31587 messages
2017-09-26 06:58:16Robert Gomułkacreate