[New-bugs-announce] [issue26767] Inconsistant error messages for failed attribute modification

Serhiy Storchaka report at bugs.python.org
Fri Apr 15 06:10:32 EDT 2016


New submission from Serhiy Storchaka:

>>> 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 "<stdin>", line 1, in <module>
AttributeError: attribute 'numerator' of 'int' objects is not writable
>>> del obj.to_bytes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: to_bytes
>>> del obj.from_bytes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: from_bytes
>>> del obj.a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't delete attribute
>>> del obj.b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't delete attribute
>>> del obj.y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: y
>>> obj.numerator = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: attribute 'numerator' of 'int' objects is not writable
>>> obj.a = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
>>> obj.c = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
>>> 
>>> obj = 1
>>> del obj.numerator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: attribute 'numerator' of 'int' objects is not writable
>>> del obj.to_bytes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object attribute 'to_bytes' is read-only
>>> del obj.from_bytes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object attribute 'from_bytes' is read-only
>>> del obj.y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'y'
>>> obj.numerator = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: attribute 'numerator' of 'int' objects is not writable
>>> obj.to_bytes = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object attribute 'to_bytes' is read-only
>>> obj.from_bytes = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object attribute 'from_bytes' is read-only
>>> obj.y = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
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.

----------
components: Interpreter Core
messages: 263464
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Inconsistant error messages for failed attribute modification
type: enhancement
versions: Python 3.6

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


More information about the New-bugs-announce mailing list