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

Jonathan Brandmeyer jbrandmeyer at earthlink.net
Tue Nov 4 03:31:31 CET 2003

On Mon, 2003-11-03 at 20:34, Nikolay Mladenov wrote:

> I was also thinking of modifying the signature element to include
> type_info *(instead of just type_info->name())
> Then instead of outputing C++ signatures some kind of Python signatures
> can be generated.
> I think this would be better since the python programmer generally would
> not know about the underlying CPP code.

Since client coders for a C++ -based python extension are either a) only
familiar with the Python interface, or b) also know the C++ interface
(and can therefore presumably deduce the underlying C++ types), this
sounds FANTASTIC to me.

In my case 'client coders' are undergraduate physics students who
generally have no idea what :: means in an error message.

> My problem is that I am not exactly sure how should the python signature
> look
> (since types are not specified for python function parameters):
> something like:
>     set( [keywords.Foo] self, [int] a=0, [float] b=0.0, [str] n="")
> may be?
> Thoughts?
> Nikolay

>>> help(str) produces messages like:
 |      S.count(sub[, start[, end]]) -> int

So, square brackets have a well defined meaning in the Python "standard
library's" help system.  Functions returning void are documented as
returning None (as dict.clear()).  C-syntax type conversions are
supported in Python, so what about using parenthesis to identify type

What about:
    Foo.set( (Keywords.Foo)self, (str)n) -> None
        sets the string field of self

    Foo.set( (Keywords.Foo)self, (int)a) -> None
        sets the integer field of self

    Foo.set( (Keywords.Foo)self, (float)b) -> None
        sets the float field of self

    Foo.set( (Keywords.Foo)self, (int)a=0 [, (float)b=0.0 [,
(str)n=""]]) -> None
	sets (up to) all the fields of self

(e-mail spacing is going to make a hash of that, but I hope you see what
I mean).
-Jonathan Brandmeyer

More information about the Cplusplus-sig mailing list