[issue19025] Deleting attribute of Enum gives misleading error message

Ethan Furman report at bugs.python.org
Sun Sep 15 20:01:03 CEST 2013


Ethan Furman added the comment:

As for the error messages (going in reverse order):

==========================================================================
--> del cute_cat.name
Traceback (most recent call last):
...
AttributeError: can't delete attribute
==========================================================================

This is the same error given by @property.


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

This is correct.  Only Enum members get special treatment.


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

There are two errors here: LONELY_WOLF does not exist, and an operation is being attempted that is not supported.  Of those two, attempting the unsupported operation is the more serious, and should be the reported error.  (Yes, dealing with multiple errors at once can often be confusing.)


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

This one I am not sure about (much as I am not sure about __getattr__ in #19011).  Enum members are virtual, and don't actually live in the class namespace.  I'm inclined to leave the existing behavior as is, but if we choose to change one, we should change both.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19025>
_______________________________________


More information about the Python-bugs-list mailing list