From 912feec119a9588c7a2c731dff321d51d1969bb8 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Fri, 1 Apr 2016 12:17:03 +0200 Subject: [PATCH] improve debug error message when default parameter construction fails --- include/pybind11/attr.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index 8c77a4127..759feed7e 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -233,11 +233,17 @@ struct process_attribute> : process_attribute_default> { #if !defined(NDEBUG) std::string descr(typeid(T).name()); detail::clean_type_id(descr); - if (r->class_) - descr += " in method of " + (std::string) r->class_.str(); + descr = "'" + std::string(a.name) + ": " + descr + "'"; + if (r->class_) { + if (r->name) + descr += " in method '" + (std::string) r->class_.str() + "." + (std::string) r->name + "'"; + else + descr += " in method of '" + (std::string) r->class_.str() + "'"; + } else if (r->name) { + descr += " in function named '" + (std::string) r->name + "'"; + } pybind11_fail("arg(): could not convert default keyword argument " - "of type " + descr + - " into a Python object (type not registered yet?)"); + + descr + " into a Python object (type not registered yet?)"); #else pybind11_fail("arg(): could not convert default keyword argument " "into a Python object (type not registered yet?). "