classification
Title: Inconsistant error messages for failed attribute modification
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, serhiy.storchaka, xtreak
Priority: low Keywords:

Created on 2016-04-15 10:10 by serhiy.storchaka, last changed 2019-12-20 17:48 by serhiy.storchaka.

Messages (3)
msg263464 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-15 10:10
>>> 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.
msg358717 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-12-20 16:25
> I think it would be nice to unify error messages and make them more specific.

How can they can be more specific when they are unified?
msg358724 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-12-20 17:48
Not all error messages contain an attribute name, an object type name and a reason.
History
Date User Action Args
2019-12-20 17:48:28serhiy.storchakasetmessages: + msg358724
2019-12-20 16:25:54BTaskayasetnosy: + BTaskaya

messages: + msg358717
versions: + Python 3.9, - Python 3.6
2018-09-21 11:58:15xtreaksetnosy: + xtreak
2016-04-17 17:27:45serhiy.storchakasetpriority: normal -> low
2016-04-15 10:10:32serhiy.storchakacreate