[Cython] autodoc function/method signatures
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Wed Sep 3 18:34:23 CEST 2008
Lisandro Dalcin wrote:
> On Tue, Sep 2, 2008 at 1:25 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:
>> Hi,
>>
>> Lisandro Dalcin wrote:
>>> Would it be possible to tell Cython/Pyrex to add a line in docstings
>>> with function/method signatures?
>> I bet you're asking because of epydoc & friends.
>
> Not only those!. If you use IPython, or even built-in help(), you
> cannot get the signature.
Well, if anybody wants to help with this one, here's how to do it:
(0. Create a feature request ticket :-) )
1. Create a new file TypedTreeTransforms.py
2. Write a transform that intercepts the functions (have a look at
ParseTreeTransforms.py for examples). For a FuncDefNode the docstring is
available in "node.doc" (and you can simply change it!) and information
about the arguments are available in "node.local_scope.arg_entries".
Note that node.doc must probably not be a regular string but an instance
of Utils.EncodedString.
3. Write code in the pipeline creation in Main.py (search for pipeline)
to insert an instance of your transform if and only if a command line
argument (CmdLine.py, options at bottom of Main.py) was passed. (You can
insert None without harm, that makes the code cleaner.) It you opt for
making it a compiler directive (so that it can be turned on/off for
individual functions) then have a look at Options.py and the "options"
attribute of all nodes.
Finally, when writing a transform, "print node.dump()" is your friend.
--
Dag Sverre
More information about the Cython-dev
mailing list