Boost C++ Libraries: Ticket #3710: error incorrect when calling boost::python function via functools.partial https://svn.boost.org/trac10/ticket/3710 <p> Neal Becker wrote: </p> <blockquote class="citation"> <p> Has anyone noticed that a function created with boost::python using args() to give keyword arguments doesn't seem to work with functools.partial keyword arguments (but does with positional args)? </p> <p> For example, I have this function: </p> <blockquote> <p> class_&lt;boost_uniform_real_wrap&gt; </p> <blockquote> <p> ("uniform_real", "Uniform float distribution", bp::init&lt;rng_t&amp;,double,double&gt;( (bp::arg ("rng"), </p> <blockquote> <p> bp::arg ("min"), bp::arg ("max"))... </p> </blockquote> </blockquote> </blockquote> <p> Then: from functools import partial f = partial (uniform_real, rng=rng1) &lt;&lt; using keyword doesn't work f (1,2) <a class="missing wiki">ArgumentError</a>: Python argument types in </p> <blockquote> <p> uniform_real.<span class="underline">init</span>(uniform_real, int, int) </p> </blockquote> <p> did not match C++ signature: </p> <blockquote> <p> <span class="underline">init</span>(_object*, boost::random::mersenne_twister&lt;unsigned int, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18, 3346425566u&gt; {lvalue} rng, double min, double max) </p> </blockquote> <p> But this works: from functools import partial f = partial (uniform_real, rng1) &lt;&lt; pos arg does work </p> <p> In <a class="changeset" href="https://svn.boost.org/trac10/changeset/27" title="*** empty log message *** ">[27]</a>: f(1,2) Out<a class="changeset" href="https://svn.boost.org/trac10/changeset/27" title="*** empty log message *** ">[27]</a>: uniform_real(1,2) </p> </blockquote> <p> That doesn't work for pure python functions either: </p> <blockquote class="citation"> <blockquote class="citation"> <blockquote class="citation"> <p> def f(x,y,z): return x*100 + y*10 + z </p> </blockquote> </blockquote> </blockquote> <p> ... </p> <blockquote class="citation"> <blockquote class="citation"> <blockquote class="citation"> <p> from functools import partial as p p(f,x=1)(2,3) </p> </blockquote> </blockquote> </blockquote> <p> Traceback (most recent call last): </p> <blockquote> <p> File "&lt;stdin&gt;", line 1, in &lt;module&gt; </p> </blockquote> <p> <a class="missing wiki">TypeError</a>: f() got multiple values for keyword argument 'x' </p> <blockquote class="citation"> <blockquote class="citation"> <blockquote class="citation"> <p> p(f,x=1)(y=2,z=3) </p> </blockquote> </blockquote> </blockquote> <p> 123 </p> <blockquote class="citation"> <blockquote class="citation"> <blockquote class="citation"> <p> p(f,1)(2,3) </p> </blockquote> </blockquote> </blockquote> <p> 123 </p> <p> The error message is misleading for sure. Boost.python is going through a list of overloads and trying them in order; if it runs out of overloads, it says nothing matched. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3710 Trac 1.4.3 anonymous Thu, 03 Dec 2009 18:55:40 GMT owner changed https://svn.boost.org/trac10/ticket/3710#comment:1 https://svn.boost.org/trac10/ticket/3710#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Dave Abrahams</span> to <span class="trac-author">troy d. straszheim</span> </li> </ul> Ticket troy d. straszheim Thu, 03 Dec 2009 21:14:03 GMT <link>https://svn.boost.org/trac10/ticket/3710#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3710#comment:2</guid> <description> <p> For the record, here's a variation on the same theme. It doesn't have anything to do with functools, it is another symptom of our first-match overload resolution algorithm: </p> <pre class="wiki">int addem(int x, int y, int z) { return x*100 + y*10 + z; } BOOST_PYTHON_MODULE(functools_playnice_ext) { def("addem", &amp;addem, (arg("x"), arg("y"), arg("z"))); } &gt;&gt;&gt; from functools_playnice_ext import addem &gt;&gt;&gt; addem(1, 8, 2, x=4) Traceback (most recent call last): ... ArgumentError: Python argument types in functools_playnice_ext.addem(int, int, int) did not match C++ signature: addem(int x, int y, int z) </pre> </description> <category>Ticket</category> </item> </channel> </rss>