[Python-Dev] Misleading error message from PyObject_GenericSetAttr (original) (raw)
Guido van Rossum guido at python.org
Mon Jun 19 17🔞15 CEST 2006
- Previous message: [Python-Dev] Misleading error message from PyObject_GenericSetAttr
- Next message: [Python-Dev] Misleading error message from PyObject_GenericSetAttr
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 6/14/06, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:
When an extension type Foo defines tpgetattr, but leaves tpsetattr 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 tpgetattr. It would be better to change the message to "'Foo' object has only read-only attributes (assign to .bar)" as in the case tpsetattro == tpsetattr == NULL in PyObjectSetAttr .
I agree. Can you submit a patch to SF please?
I've also noticed that the exceptions raised from PyObjectSetAttr are TypeErrors. Shouldn't PyObjectGenericSetAttr raise a TypeError if tpsetattr is null but tpgetattr is not? This would be consistent with the errors from read-only descriptors.
Attempting to obtain complete consistency between TypeError and AttributeError is hopeless. But if you want to submit a patch to reduce a particular bit of inconsistency (without increasing it elsewhere) it might well be accepted.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Misleading error message from PyObject_GenericSetAttr
- Next message: [Python-Dev] Misleading error message from PyObject_GenericSetAttr
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]