Extension functions and 'help'

When I call


(Mod is a C extension module), I get the output

Help on method_descriptor:


What do I need to do so that the help output is of the form

Help on method f in module Mod:

f(x, y, z)

like it is for random.Random.shuffle, for example?

My PyMethodDef entry is currently:

{ "f", f, METH_VARARGS, "doc_string" }


You cannot. The inspect module, which is what 'pydoc' and 'help()' use, has no way of figuring out what the exact signature of a C function is. The best you can do is what the builtin functions do: include the signature in the first line of the docstring:

>>> help(range)
Help on built-in function range in module __builtin__:

    range([start,] stop[, step]) -> list of integers


The reason random.shuffle's docstring looks "correct" is that it isn't a C function. It's a function written in Python.

Thomas's answer is right on, of course.

I would simply add that many C extension modules have a Python "wrapper" around them so that they can support standard function signatures and other dynamic-language features (such as the descriptor protocol).

Need Your Help

JQuery multiple class selectors fails in IE6

javascript jquery internet-explorer-6

I make use of class selectors in JQuery and this works fine but in IE6 this fails as it does not apply the width I would like.