[C++-sig] pybindgen add_function_as_constructor

Gustavo Carneiro gjcarneiro at gmail.com
Tue Apr 28 12:23:43 CEST 2009


2009/4/27 Robin Gilks <robin.gilks at tait.co.nz>

> Gustavo Carneiro wrote:
>
>>
>> Sounds good.
>>
>> Sorry I wasn't online to help with the other questions.  I assume those
>> problems are solved, if not please ask again the questions.
>>
>>
>>    Where I've got to now is I can't find how to declare a docstring
>>    for a function or method.
>>
>>
>> Doesn't this work?
>>
>>     module.add_function(..., docstring="this is a docstring")
>>
>> OK, looking at the code I found two bugs in pybindgen wrt docstrings:
>>
>>     1. there is a bug with handling docstrings with overloaded functions;
>> they will only work if the function is not overloaded with another function
>> with the same name;
>>
>>     2. I forgot to add a docstring parameter to method objects.  But it's
>> a simple workaround, just:
>>
>>        method = MyClass.add_method(...)
>>        method.docstring = "this is a docstring"
>>
>>    Again, only works if the method is not overloaded.
>>
>>
>
> Thanks Gustavo
>
> That gave me all the clues I needed. I've only just started using Python so
> my patch (below) is very much derived from the 'suck it and see' philosophy.
> It seems to work for me however!!
>
> diff -PurN pybindgen/cppmethod.py
> ../../pybindgen-0.10.0/pybindgen/cppmethod.py
> --- pybindgen/cppmethod.py      2008-11-08 07:55:41.000000000 +1300
> +++ ../../pybindgen-0.10.0/pybindgen/cppmethod.py       2009-04-27
> 23:05:27.000000000 +1200
> @@ -19,7 +19,7 @@
>    Class that generates a wrapper to a C++ class method
>    """
>
> -    def __init__(self, method_name, return_value, parameters,
> is_static=False,
> +    def __init__(self, method_name, return_value, parameters,
> is_static=False, docstring=None,
>                 template_parameters=(), is_virtual=False, is_const=False,
>                 unblock_threads=None, is_pure_virtual=False,
>                 custom_template_method_name=None, visibility='public',
> @@ -95,7 +95,7 @@
>        #self.static_decl = True
>        self._class = None
>        self._helper_class = None
> -        self.docstring = None
> +        self.docstring = docstring
>        self.wrapper_base_name = None
>        self.wrapper_actual_name = None
>        self.return_value = None
>
>
>
Thanks, applied.

-- 
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090428/dd97f5df/attachment.htm>


More information about the Cplusplus-sig mailing list