[C++-sig] Boost.Python.function.__signatures__
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Wed Jul 20 02:17:26 CEST 2005
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