Skip to content

Commit 0d108f1

Browse files
committed
Better error reporting for overload resolution failures, ideas thanks
to Nikolay Mladenov. [SVN r20770]
1 parent 4aca2ca commit 0d108f1

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/object/function.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <boost/python/tuple.hpp>
1717
#include <boost/python/list.hpp>
1818

19+
#include <boost/python/detail/api_placeholder.hpp>
1920
#include <boost/python/detail/signature.hpp>
2021
#include <boost/mpl/vector/vector10.hpp>
2122

@@ -233,13 +234,13 @@ void function::argument_error(PyObject* args, PyObject* keywords) const
233234
object message = "Python argument types in\n %s.%s("
234235
% make_tuple(this->m_namespace, this->m_name);
235236

236-
list actual;
237+
list actual_args;
237238
for (int i = 0; i < PyTuple_Size(args); ++i)
238239
{
239240
char const* name = PyTuple_GetItem(args, i)->ob_type->tp_name;
240-
actual.append(str(name));
241+
actual_args.append(str(name));
241242
}
242-
message += str(", ").join(actual);
243+
message += str(", ").join(actual_args);
243244
message += ")\ndid not match C++ signature:\n ";
244245

245246
list signatures;
@@ -248,27 +249,39 @@ void function::argument_error(PyObject* args, PyObject* keywords) const
248249
py_function const& impl = f->m_fn;
249250

250251
python::detail::signature_element const* s
251-
= impl.signature();
252+
= impl.signature() + 1; // skip over return type
252253

253-
list formal;
254+
list formal_params;
254255
if (impl.max_arity() == 0)
255-
formal.append("void");
256+
formal_params.append("void");
256257

257-
for (unsigned n = 1; n <= impl.max_arity(); ++n)
258+
for (unsigned n = 0; n < impl.max_arity(); ++n)
258259
{
259260
if (s[n].basename == 0)
260261
{
261-
formal.append("...");
262+
formal_params.append("...");
262263
break;
263264
}
265+
266+
str param(s[n].basename);
267+
if (s[n].lvalue)
268+
param += " {lvalue}";
264269

265-
formal.append(
266-
str(s[n].basename) + (s[n].lvalue ? " {lvalue}" : "")
267-
);
270+
if (f->m_arg_names) // None or empty tuple will test false
271+
{
272+
object kv(f->m_arg_names[n]);
273+
if (kv)
274+
{
275+
char const* const fmt = len(kv) > 1 ? " %s=%r" : " %s";
276+
param += fmt % kv;
277+
}
278+
}
279+
280+
formal_params.append(param);
268281
}
269282

270283
signatures.append(
271-
"%s(%s)" % make_tuple(f->m_name, str(", ").join(formal))
284+
"%s(%s)" % make_tuple(f->m_name, str(", ").join(formal_params))
272285
);
273286
}
274287

0 commit comments

Comments
 (0)