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 ncoghlan
Recipients ncoghlan
Date 2013-05-12.06:51:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368341497.6.0.896861896968.issue17959@psf.upfronthosting.co.za>
In-reply-to
Content
Creating this as a separate issue so as not to delay incorporation of the accepted PEP.

One legitimate criticism of the accepted PEP 435 is that the combination of requiring explicit assignment of values *and* allowing aliasing by default is that aliases may be created inadvertently. I believe we can actually do better than the initial implementation by making the following work:

>>> class Shape(Enum):
...   square = 2
...   diamond = 1
...   circle = 3
...   alias_for_square = square
...
>>> Shape.square
<Shape.square: 2>
>>> Shape.alias_for_square
<Shape.square: 2>
>>> Shape(2)
<Shape.square: 2>

While *disallowing* the following: 

>>> class Shape(Enum):
...   square = 2
...   diamond = 1
...   circle = 3
...   alias_for_square = 2
...

How, do you ask? By wrapping non-descriptors on assignment in a placeholder type, and keeping track of which values we have already seen. If a new attribute is mapped to a placeholder, then that's fine, we accept it as an explicit declaration of an alias. However, if it's mapped directly to a repeat value, then that would be disallowed (as it was in earlier versions of the PEP).
History
Date User Action Args
2013-05-12 06:51:37ncoghlansetrecipients: + ncoghlan
2013-05-12 06:51:37ncoghlansetmessageid: <1368341497.6.0.896861896968.issue17959@psf.upfronthosting.co.za>
2013-05-12 06:51:37ncoghlanlinkissue17959 messages
2013-05-12 06:51:37ncoghlancreate