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.

classification
Title: Misleading error message from PyObject_GenericSetAttr
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, georg.brandl
Priority: normal Keywords:

Created on 2006-06-15 16:24 by belopolsky, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg28802 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2006-06-15 16:24
When an extension type Foo defines tp_getattr, but
leaves tp_setattr NULL, an attempt to set an attribute
bar results in an AttributeError with the message
"'Foo' object has no attribute 'bar'".  This message is
misleading because the object may have the attribute
'bar' as implemented in tp_getattr.  It would be better
to change the message to "'Foo' object has only
read-only attributes (assign to .bar)" as in the case
tp_setattro == tp_setattr == NULL in  PyObject_SetAttr .

I've also noticed that the exceptions raised from
PyObject_SetAttr are TypeErrors. Shouldn't
PyObject_GenericSetAttr raise a TypeError if tp_setattr
is null but tp_getattr is not?  This would be
consistent with the errors from read-only descriptors.
msg28803 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-06-18 22:19
Logged In: YES 
user_id=849994

Unfortunately the message "object has only readonly attrs"
isn't quite right either, since there may be other
attributes that can be set and deleted. I tried to come up
with a better message but couldn't find one.

The exception type cannot be changed for sure, because of
backwards compatibility.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43508
2006-06-15 16:24:45belopolskycreate