I am currently trying to write a Python extension module using the Python C API.
In some of my objects, I am defining read-only attributes using PyGetSetDef
descriptors which look as follows:
PyGetSetDef get_set_descriptors[] = {
{
(char*) "foo",
(getter) get_foo,
(setter) 0,
(char*) "Docstring",
NULL
},
{ NULL, NULL, NULL, NULL, NULL } // sentinel
};
Now, I am trying to generate a documentation file for my extension module. For this purpose, I am using the inspect
module in a Python script to iterate over all classes, methods, and attributes for each class in the module.
When looking at the Object
instance corresponding to my get-set descriptor, I find members for both __set__
and __get__
- without any way to differentiate whether the corresponding properties are meant to be read-only (or write-only, FWIW) or not.
Is there a way to programmatically check whether class attributes defined in Python extension modules are read-only using introspection?