Thread: Re: [Epydoc-devel] [C++-sig] Better introspection/apidoc extraction support?
Brought to you by:
edloper
From: Hans M. <me...@in...> - 2007-05-15 11:37:45
|
Hi! Am Montag, 14. Mai 2007 17:59:00 schrieb Ralf W. Grosse-Kunstleve: > I did the implementation of the "docstring_options" feature. I'm not aware > of plans to work on this, but I'm interested to at least learn what could > be done to better support epydoc. If it is not too time-consuming I'd be > willing to work on it a bit. Great! > > The epydoc developers would like to support boost::python function > > introspection. In boost 1.34.0, there is support for C++ signatures > > appended to the docstrings, but it would be better AFAICS if > > boost::python would additionally provide means for extracting the > > argument names and default values via ("half-private") attributes, > > similar to CPython. > > How exactly does this work? Are there web pages about this? Not that I know of. AFAICS, there is no public API for that (that's why I wrote "half-private"), but if you look at a functions func_code.co_XXX and func_defaults properties, you see that there is a lot of internal information available in CPython. Then, there is the inspect module (implemented in python), which uses the above internal stuff to offer a more convenient API. E.g. inspect.getargspec() uses func_code.co_varnames[:func_code.co_argcount] to query the argument names, func_code.co_flags to determine whether the function has *args or **kwargs parameters (4/8 bitflags), ... I would think that basically *any* API within boost::python functions would be OK, since there is no official way beyond inspect. (Of course, it would be best if the inspect module would become compatible with boost::python some day, so apidoc projects do not have to duplicate code..) -- Ciao, / / /--/ / / ANS |
From: Hans M. <me...@in...> - 2007-05-15 13:01:51
|
Hi! Am Dienstag, 15. Mai 2007 14:12:07 schrieb English, Mark: > For an introspection example, there was a signature.py drifting around > which I'm having trouble tracking down, written I believe by Neel > Krishnaswami. There's a copy here: > http://funformkit.sourceforge.net/FunFormKit/Signature.py That looks like a predecessor / alternative to the std. 'inspect' module. (And does not yet work with boost::python or course.) > Speaking of signatures, have you looked at the draft Pep 362 ? > http://www.python.org/dev/peps/pep-0362/ That PEP is very interesting indeed. Since it describes a complete API, it looks like a perfect implementation goal for BPL. (Eager/lazy creation does not really matter here, as long as BPL functions get a proper __signature__ attribute.) Ralf, what do you think? -- Ciao, / / /--/ / / ANS |
From: Hans M. <me...@in...> - 2007-05-25 12:41:11
Attachments:
boost_separated_cppsignatures.diff
|
Hi Ralf! Am Dienstag, 22. Mai 2007 19:14:42 schrieb Ralf W. Grosse-Kunstleve: > Sorry, this looks like more work than I'm able to squeeze in. I was hoping > for a well-established, time-tested API, but it looks more like work in > progress. That's a pity, but I can understand it. OTOH, I don't think there is much progress ATM, as long as PEP 362 is not implemented. (Is there a reason you did not reply to my later post where I mentioned http://www.python.org/dev/peps/pep-0362/ - I just want to make sure you saw it.) I indeed wrote a parser for the C++ signatures for epydoc, but it is quite complicated since I have to - parse arbitrary C++ types (templates with argument literals, namespaces, ...), which made me hack together a rather largish pyparsing-based parser (and as you know, writing a C++ parser is not what you wanna do..) - parse arbitrary Python __repr__ output for the default arguments. Again, that is not doable with just regular expressions, also the __repr__ can be basically anything, so it cannot be 100% safe. It would be much better if there was an API to extract argument names and default values. > The current docstring support isn't all that complicated. Look in > boost/libs/python/src/object/function.cpp, mainly function::signature(). When using epydoc, I noticed that the resulting docstrings are no valid reST anymore if the original docstring does not end with a \n: """foo bar C++ signature: test(void) -> void""" However, this would be a valid description list: """foo bar C++ signature: test(void) -> void""" Would it make sense to just add two \n instead of one in libs/python/src/object/function.cpp:510? Or look at the attached patch, which also cares about docstrings to which a \n has manually been appended for boost 1.34.0beta + epydoc support. That does not yet lead to a very pretty output, but it is a minimal change that makes epydoc w/ reST work at least, without further modifications. -- Ciao, / / /--/ / / ANS |