Issue 26767: Inconsistant error messages for failed attribute modification (original) (raw)
class I(int): ... @property ... def a(self): pass ... @property ... def b(self): pass ... @b.setter ... def b(self, value): pass ... @property ... def c(self): pass ... @c.deleter ... def c(self): pass ... obj = I() del obj.numerator Traceback (most recent call last): File "", line 1, in AttributeError: attribute 'numerator' of 'int' objects is not writable del obj.to_bytes Traceback (most recent call last): File "", line 1, in AttributeError: to_bytes del obj.from_bytes Traceback (most recent call last): File "", line 1, in AttributeError: from_bytes del obj.a Traceback (most recent call last): File "", line 1, in AttributeError: can't delete attribute del obj.b Traceback (most recent call last): File "", line 1, in AttributeError: can't delete attribute del obj.y Traceback (most recent call last): File "", line 1, in AttributeError: y obj.numerator = 1 Traceback (most recent call last): File "", line 1, in AttributeError: attribute 'numerator' of 'int' objects is not writable obj.a = 1 Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute obj.c = 1 Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute
obj = 1 del obj.numerator Traceback (most recent call last): File "", line 1, in AttributeError: attribute 'numerator' of 'int' objects is not writable del obj.to_bytes Traceback (most recent call last): File "", line 1, in AttributeError: 'int' object attribute 'to_bytes' is read-only del obj.from_bytes Traceback (most recent call last): File "", line 1, in AttributeError: 'int' object attribute 'from_bytes' is read-only del obj.y Traceback (most recent call last): File "", line 1, in AttributeError: 'int' object has no attribute 'y' obj.numerator = 1 Traceback (most recent call last): File "", line 1, in AttributeError: attribute 'numerator' of 'int' objects is not writable obj.to_bytes = 1 Traceback (most recent call last): File "", line 1, in AttributeError: 'int' object attribute 'to_bytes' is read-only obj.from_bytes = 1 Traceback (most recent call last): File "", line 1, in AttributeError: 'int' object attribute 'from_bytes' is read-only obj.y = 1 Traceback (most recent call last): File "", line 1, in AttributeError: 'int' object has no attribute 'y'
Different error messages are used in errors when try to modify non-existing or read-only attribute. This depends on the existing dict and the way how the attribute is resolved.
- just the attribute name
- "'%.50s' object has no attribute '%U'"
- "'%.50s' object attribute '%U' is read-only"
- "attribute '%V' of '%.100s' objects is not writable"
I think it would be nice to unify error messages and make them more specific.