[C++-sig] Overloading & keyword args bug?

Alex Mohr amohr at pixar.com
Thu Jun 8 18:57:10 CEST 2006


> I am surprised any of your tests works.
> AFAIK you need to make several changes:
> 
> BOOST_PYTHON_FUNCTION_OVERLOADS(f1_overloads, f1, 1, 3)
> BOOST_PYTHON_FUNCTION_OVERLOADS(f2_overloads, f2, 2, 4)
> 
> you have to give your C++ functions default arguments.

Why is this?  Suppose I don't want the functions to have default args in 
C++ -- only in python.  Regardless, since I'm providing default values 
for the keyword arguments at def() time, I think boost.python will 
always have to call my function with a full set of arguments.

> you have to define all arg(), i.e something like
> 
>   def("f", f1, f1_overloads((arg("a1"), arg("x")=3, arg("y")=4)));
> 
> At least this is what I do all the time.

I don't think that is (or should be) required.  Suppose I want some 
positional-only arguments.  According to the documentation for def, you 
may specify no more keyword arguments than the arity of f, so it seems 
like if you specify fewer, then they are taken as the last C++ arguments.

Note that if I remove one of the overloads (one of the def lines) then 
everything works as expected.

Perhaps David can shed some light.

Alex



More information about the Cplusplus-sig mailing list