[C++-sig] Boost.Python.function.__signatures__

Nikolay Mladenov nickm at sitius.com
Thu Jul 21 19:38:58 CEST 2005


I worked on that a bit in the past and I had some initial work committed
in branch function_signature_patches_1_31. I also have some more
uncommitted changes.
A week ago I started to work on it again and I will try to merge it with
the main branch.

Currently help on our boost.python modules is working like that:

>>> help(samath.Plane3.normal)
Help on method normal:

normal(...) unbound sitius.samath.Plane3 method
    normal( (Plane3)self) -> Vector3
    normal( (Plane3)self, (Vector3)dir [, (int)is_unit=0]) -> Plane3


It is using the Pythonic type names and the argument names and default
values if available.


Nikolay

"Ralf W. Grosse-Kunstleve" wrote:
> 
> Hi David,
> 
> Often I'd like to quickly find out the signatures of C++ functions wrapped with
> Boost.Python. Usually I use one of two approaches: 1. look in the wrapper
> sources, 2. call the function with no or bogus arguments to provoke a
> traceback, e.g.:
> 
> % python
> Python 2.4.1 (#1, Apr  7 2005, 10:15:30)
> [GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-113)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from boost import rational
> >>> rational.lcm()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> Boost.Python.ArgumentError: Python argument types in
>     boost_rational_ext.lcm()
> did not match C++ signature:
>     lcm(int, int)
> >>>
> 
> Both options are not very elegant. I'd really like something more direct and
> easier to explain. This lead me to the idea of implementing
> Boost.Python.function.__signatures__:
> 
> http://cci.lbl.gov/~rwgk/boost_python/signatures/
> 
> Here you'll find the diffs for function.hpp and function.cpp, and also the
> patched versions of both.
> 
> It works like this:
> 
> >>> print boost_rational_ext.lcm.__signatures__
> ['lcm(int, int)']
> 
> I.e. __signatures__ returns a list of strings with the signatures formatted as
> in the traceback. Is this a good direction to take?
> 
> I know it needs more work (similar patch for member functions (?), tests on all
> platforms, updated docs). I'll do this if I get positive feedback.
> 
> Cheers,
>         Ralf
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com




More information about the Cplusplus-sig mailing list