[C++-sig] Re: function::argument_error / overloads & docstrings

Nikolay Mladenov nickm at sitius.com
Wed Nov 5 06:23:21 CET 2003



Nikolay Mladenov wrote:
> 
> If you have the following module:
> struct Foo
> {
>     void set(int a=0, double b=0, const std::string &n=std::string())
>     {
>         a_ = a;
>         b_ = b;
>         n_ = n;
>     }
> 
> private:
> .....................
> };
> 
> using namespace boost::python;
> BOOST_PYTHON_MODULE(keywords)
> {
>    class_<Foo>("Foo"
>        , init<int
>               , double
>               , const std::string &
>               >(
>               (  arg("a") = 0
>               , arg("b") = 0.0
>               , arg("n") = std::string()
>               ))
>         )
>       .def("set"
>             , (void (Foo::*)(int , double , const std::string &)
> )&Foo::set
>             , (arg("self"),arg("a") = 0, arg("b") = 0.0, arg("n") =
> std::string())
>             , "Sets all the fields of self")
>      ...........................
>       ;
> 
> }
> #include "module_tail.cpp"
> ////////////////////////////////////////
> 
> with what I currently have (cvs patched by me) I get:
> 
> >>> import keywords
> >>> help(keywords.Foo.set)
> 
> Help on method set:
> 
> set(...) unbound keywords.Foo method
>     set(struct Foo self, int a=0, double b=0.0, class
> _STL::basic_string<char,struct std::char_traits<char>,class
> _STL::allocator<char> > n="")
>         Sets all the fields of self
> (END)
> >>>
> 

I now think that this is too intrusive and there should be a way
to specify whether or not the signature will be attached to the
docstring.
May be like that:

 def ("f", &f, "f's docstring")
 def ("g", &g, "%s\n\t g's docstring")
.....
>>> print f.__doc__
f's docstring
>>> print g.__doc__
g() -> None
	g's docstring


Nikolay





More information about the Cplusplus-sig mailing list