From 4fee179900c9c7c9fb3731f04fa98f851ba3787d Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Tue, 9 Feb 2016 09:46:11 +0100 Subject: [PATCH] better debug info when arg::operator=() fails --- include/pybind11/attr.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index cfa509030..15d5982aa 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -229,11 +229,21 @@ struct process_attribute> : process_attribute_default> { object o = object(detail::type_caster::type>::cast( a.value, return_value_policy::automatic, handle()), false); - if (!o) - pybind11_fail("arg(): could not convert default keyword " - "argument into a Python object (type not " - "registered yet?)"); - + if (!o) { +#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(); + pybind11_fail("arg(): could not convert default keyword argument " + "of type " + 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?). " + "Compile in debug mode for more information."); +#endif + } r->args.emplace_back(a.name, a.descr, o.release()); } };