[Python-Dev] Misleading error message from PyObject_GenericSetAttr

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Jun 26 21:54:49 CEST 2006


On 6/19/06, Guido van Rossum <guido at python.org> wrote:
> On 6/14/06, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:
> > ... 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 agree. Can you submit a patch to SF please?
>
Please see:

https://sourceforge.net/tracker/index.php?func=detail&aid=1512942&group_id=5470&atid=305470

I've tested the patch by setting tp_setattr to 0 in Xxo_Type.  With the patch:

>>> import xx
>>> x = xx.new()
>>> x.a = 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'xxmodule.Xxo' object has only read-only attributes
(assign to .a)
>>> del x.a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'xxmodule.Xxo' object has only read-only attributes (del .a)

Note that this log reveals a small inaccuracy in xxmodule.c : the
module name is "xx," but Xxo type name is "xxmodule.Xxo."  Should I
submit a patch fixing that?


More information about the Python-Dev mailing list