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 vajrasky
Recipients ethan.furman, vajrasky
Date 2013-09-15.15:15:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1379258110.64.0.0894426931246.issue19025@psf.upfronthosting.co.za>
In-reply-to
Content
>>> from enum import Enum
>>> class MyPet(Enum):
...   CUTE_CAT = 1
...   VIGOROUS_DOG = 2
...   UGLY_BLOBFISH = 3
...   PROMISCUOUS_BONOBO = 4
...   def spam(cls): pass
... 
>>> del MyPet.CUTE_CAT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: CUTE_CAT

This is misleading. I have CUTE_CAT attribute in Enum. It should throw TypeError exception.

>>> del MyPet.LONELY_WOLF
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: LONELY_WOLF

This is correct.

>>> del MyPet['CUTE_CAT']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'EnumMeta' object does not support item deletion

I think this behaviour is correct.

>>> del MyPet['LONELY_WOLF']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'EnumMeta' object does not support item deletion

This behaviour is somewhat misleading. I don't have LONELY_WOLF item.

>>> del MyPet.spam
>>> hasattr(MyPet, 'spam')
False

This is correct. We should be able to delete method from Enum class, or shouldn't we?

>>> cute_cat = MyPet.CUTE_CAT
>>> del cute_cat.name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sky/Code/python/programming_language/cpython/Lib/enum.py", line 29, in __delete__
    raise AttributeError("can't delete attribute")
AttributeError: can't delete attribute

This is *maybe" correct. But shouldn't it be TypeError exception?

All the exception messages related with deleting attribute in Python codebase are using TypeError exception (with one exception in pyexpat on which it uses RuntimeError exception).

Attached the patch to handle the attribute deletion correctly.

For now, I don't change the exception for the last case (del MyPet.CUTE_CAT.name) because maybe there is an exception case for enum.
History
Date User Action Args
2013-09-15 15:15:10vajraskysetrecipients: + vajrasky, ethan.furman
2013-09-15 15:15:10vajraskysetmessageid: <1379258110.64.0.0894426931246.issue19025@psf.upfronthosting.co.za>
2013-09-15 15:15:10vajraskylinkissue19025 messages
2013-09-15 15:15:10vajraskycreate