CPython detecting read-only attributes.

Jeremy Lowery jslowery at hotmail.com
Fri Sep 13 18:21:46 EDT 2002


I'm implementing an extension type in CPython, using the new getsetlist
tp_getset.

I have defined my own tp_setattro function, and my question is: What would
be the easiest way to detect the attempt to write to a readonly attribute.

Scouring PyObject_GenericSetAttr, I see that it always returns -1 on fail,
but that is if it doesn't find a corresponding match or not, and the same
exception is raised PyExc_AttributeError.

I am trying to use the builtin functionality and then, if the attribute is
not found and only if it is not found, I would like to store it in a PyDict
myself.

Is there a better function around to do the Attribute Lookup/setting for the
builtin? I haven't been able to find documentation for these new API
functions (added 2.2) in the reference.

Thanks,
J Lowery







More information about the Python-list mailing list