C API PyErr_Clear vs PyObject_HasAttrString

Andrew MacIntyre andymac at bullseye.apana.org.au
Mon Nov 29 08:35:28 EST 2004


On Sun, 28 Nov 2004, Robin Becker wrote:

> > I had a look at the source (from a CVS checkout this morning), and the
> > only thing that looks like a source of such trouble would be an extension
> > class with a tp_getattr implementation.
>
> It is such a beast, but the exciting test case looks like
>
> #####################
> import _test
> g=_test.gstate()
>
> for a in ('strokeColor','strokeColor'):
> 	try:
> 		setattr(g,a,(1,2,3))
> 		print 'Wrong handling of bad '+a
> 	except ValueError:
> 		pass
> #####################
>
> so the tp_getattr slot isn't being used.

Referring to the original C code you posted, PyObject_HasAttrString() will
call the tp_getattr routine, clearing any exceptions raised as it returns.

-------------------------------------------------------------------------
Andrew I MacIntyre                     "These thoughts are mine alone..."
E-mail: andymac at bullseye.apana.org.au  (pref) | Snail: PO Box 370
        andymac at pcug.org.au             (alt) |        Belconnen ACT 2616
Web:    http://www.andymac.org/               |        Australia



More information about the Python-list mailing list