[C++-sig] functions not showing up in pydoc
Nick Rasmussen
nick at ilm.com
Thu Feb 17 00:26:06 CET 2005
On Thu, 10 Feb 2005, Nick Rasmussen wrote:
>
> Thanks for testing it out. It's been working fine for me here
> (suse9.1 amd64 with python2.3), but I'll see if I can figure
> out what the right fix is.
>
> I took a quick look at PyCFunction_Type, and it's tp_flags are
> set to:
>
> Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
>
> Two things make me suspicious: absent is Py_TPFLAGS_BASETYPE,
> and I'm not sure if subclasses of gc-aware classes need to
> support garbage collection as well.
>
> I'll run it by our local python expert and see what he has
> to say.
I ran this question past python-dev, and they said that
one way to do this is to have PyCFunction_Type as the
__class__ attribute:
http://thread.gmane.org/gmane.comp.python.devel/66557
I'm now running boost::python with the following patch applied
(docstring concatenation and the __class__ attribute), and
this seems to be working for me.
-nick
--- libs/python/src/object/function.cpp.orig Mon Feb 7 17:11:52 2005
+++ libs/python/src/object/function.cpp Wed Feb 16 12:13:38 2005
@@ -472,7 +472,12 @@
if (doc != 0)
{
object attr_copy(attribute);
- attr_copy.attr("__doc__") = doc;
+ if (PyObject_HasAttrString(attr_copy.ptr(), "__doc__") && attr_copy.attr("__doc__")) {
+ attr_copy.attr("__doc__") += "\n\n";
+ attr_copy.attr("__doc__") += doc;
+ }
+ else
+ attr_copy.attr("__doc__") = doc;
}
}
@@ -566,11 +571,17 @@
else
return python::incref(f->name().ptr());
}
+
+ static PyObject* function_get_class(PyObject* op, void*)
+ {
+ return python::incref(reinterpret_cast<PyObject *>(&PyCFunction_Type));
+ }
}
static PyGetSetDef function_getsetlist[] = {
{"__name__", (getter)function_get_name, 0 },
{"func_name", (getter)function_get_name, 0 },
+ {"__class__", (getter)function_get_class, 0 },
{"__doc__", (getter)function_get_doc, (setter)function_set_doc},
{"func_doc", (getter)function_get_doc, (setter)function_set_doc},
{NULL} /* Sentinel */
More information about the Cplusplus-sig
mailing list