tommy said that this would be the best place to ask this question.... I'm trying to get functions wrapped via boost to show up as builtin types so that pydoc includes them when documenting the module containing them. Right now boost python functions are created using a PyTypeObject such that when inspect.isbuiltin does: return isinstance(object, types.BuiltinFunctionType) isintance returns 0. Initially I had just modified a local pydoc to document all functions with unknown source modules (since the module can't be deduced from non-python functions), but I figured that the right fix was to get boost::python functions to correctly show up as builtins, so I tried setting PyCFunction_Type as the boost function type object's tp_base, which worked fine for me using linux on amd64, but when my patch was tried out on other platforms, it ran into regression test failures: http://mail.python.org/pipermail/c++-sig/2005-February/008545.html So I have some questions: Should boost::python functions be modified in some way to show up as builtin function types or is the right fix really to patch pydoc? Is PyCFunction_Type intended to be subclassable? I noticed that it does not have Py_TPFLAGS_BASETYPE set in its tp_flags. Also, PyCFunction_Type has Py_TPFLAGS_HAVE_GC, and as the assertion failures in the testsuite seemed to be centered around object allocation/ garbage collection, so is there something related to subclassing a gc-aware class that needs to be happening (currently the boost type object doesn't support garbage collection). If subclassing PyCFunction_Type isn't the right way to make these functions be considered as builtin functions, what is? -nick
Nick Rasmussen <nick@ilm.com> writes: [five days ago]
Should boost::python functions be modified in some way to show up as builtin function types or is the right fix really to patch pydoc?
My heart leans towards the latter.
Is PyCFunction_Type intended to be subclassable?
Doesn't look like it, does it? :) More seriosly, "no". Cheers, mwh -- ARTHUR: Don't ask me how it works or I'll start to whimper. -- The Hitch-Hikers Guide to the Galaxy, Episode 11
At 02:32 PM 2/11/05 -0800, Nick Rasmussen wrote:
tommy said that this would be the best place to ask this question....
I'm trying to get functions wrapped via boost to show up as builtin types so that pydoc includes them when documenting the module containing them. Right now boost python functions are created using a PyTypeObject such that when inspect.isbuiltin does:
return isinstance(object, types.BuiltinFunctionType)
FYI, this may not be the "right" way to do this, but since 2.3 'isinstance()' looks at an object's __class__ rather than its type(), so you could perhaps include a '__class__' descriptor in your method type that returns BuiltinFunctionType and see if that works. It's a kludge, but it might let your code work with existing versions of Python.
On Feb 16, 2005, at 11:02, Phillip J. Eby wrote:
At 02:32 PM 2/11/05 -0800, Nick Rasmussen wrote:
tommy said that this would be the best place to ask this question....
I'm trying to get functions wrapped via boost to show up as builtin types so that pydoc includes them when documenting the module containing them. Right now boost python functions are created using a PyTypeObject such that when inspect.isbuiltin does:
return isinstance(object, types.BuiltinFunctionType)
FYI, this may not be the "right" way to do this, but since 2.3 'isinstance()' looks at an object's __class__ rather than its type(), so you could perhaps include a '__class__' descriptor in your method type that returns BuiltinFunctionType and see if that works.
It's a kludge, but it might let your code work with existing versions of Python.
It works in Python 2.3.0: import types class FakeBuiltin(object): __doc__ = property(lambda self: self.doc) __name__ = property(lambda self: self.name) __self__ = property(lambda self: None) __class__ = property(lambda self: types.BuiltinFunctionType) def __init__(self, name, doc): self.name = name self.doc = doc
help(FakeBuiltin("name", "name(foo, bar, baz) -> rval")) Help on built-in function name:
name(...) name(foo, bar, baz) -> rval -bob
At 11:26 AM 2/16/05 -0500, Bob Ippolito wrote:
help(FakeBuiltin("name", "name(foo, bar, baz) -> rval")) Help on built-in function name:
name(...) name(foo, bar, baz) -> rval
If you wanted to be even more ambitious, you could return FunctionType and have a fake func_code so pydoc will be able to see the argument signature directly. :)
On Feb 16, 2005, at 11:43, Phillip J. Eby wrote:
At 11:26 AM 2/16/05 -0500, Bob Ippolito wrote:
help(FakeBuiltin("name", "name(foo, bar, baz) -> rval")) Help on built-in function name:
name(...) name(foo, bar, baz) -> rval
If you wanted to be even more ambitious, you could return FunctionType and have a fake func_code so pydoc will be able to see the argument signature directly. :)
I was thinking that too, but I didn't have the energy to code it in an email :) -bob
On Wed, 16 Feb 2005, Bob Ippolito wrote:
On Feb 16, 2005, at 11:02, Phillip J. Eby wrote:
At 02:32 PM 2/11/05 -0800, Nick Rasmussen wrote:
tommy said that this would be the best place to ask this question....
I'm trying to get functions wrapped via boost to show up as builtin types so that pydoc includes them when documenting the module containing them. Right now boost python functions are created using a PyTypeObject such that when inspect.isbuiltin does:
return isinstance(object, types.BuiltinFunctionType)
FYI, this may not be the "right" way to do this, but since 2.3 'isinstance()' looks at an object's __class__ rather than its type(), so you could perhaps include a '__class__' descriptor in your method type that returns BuiltinFunctionType and see if that works.
It's a kludge, but it might let your code work with existing versions of Python.
It works in Python 2.3.0:
That seemed to do the trick for me as well, I'll run it past the boost::python folks and see what they think. many thanks -nick
participants (4)
-
Bob Ippolito -
Michael Hudson -
Nick Rasmussen -
Phillip J. Eby