[Python-Dev] Misleading error message from PyObject_GenericSetAttr (original) (raw)
Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Jun 14 23:23:30 CEST 2006
- Previous message: [Python-Dev] [Python-checkins] sqlite3 test errors - was : Re: r46936 - in python/trunk: Lib/sqlite3/test/regression.py Lib/sqlite3/test/types.py Lib/sqlite3/test/userfunctions.py Modules/_sqlite/connection.c Modules/_sqlite/cursor.c Modules/_sqlite/module.c
- Next message: [Python-Dev] Misleading error message from PyObject_GenericSetAttr
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message: [Python-Dev] [Python-checkins] sqlite3 test errors - was : Re: r46936 - in python/trunk: Lib/sqlite3/test/regression.py Lib/sqlite3/test/types.py Lib/sqlite3/test/userfunctions.py Modules/_sqlite/connection.c Modules/_sqlite/cursor.c Modules/_sqlite/module.c
- Next message: [Python-Dev] Misleading error message from PyObject_GenericSetAttr
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]