diff --git a/include/boost/python/object/function_doc_signature.hpp b/include/boost/python/object/function_doc_signature.hpp index 4f00cb38..5fa2c19d 100644 --- a/include/boost/python/object/function_doc_signature.hpp +++ b/include/boost/python/object/function_doc_signature.hpp @@ -18,7 +18,7 @@ namespace boost { namespace python { namespace objects { class function_doc_signature_generator{ - static const char * py_type_str(const python::detail::signature_element &s); + static str py_type_str(const python::detail::signature_element &s); static bool arity_cmp( function const *f1, function const *f2 ); static bool are_seq_overloads( function const *f1, function const *f2 , bool check_docs); static std::vector flatten(function const *f); diff --git a/src/object/function_doc_signature.cpp b/src/object/function_doc_signature.cpp index 41695285..c5a54988 100644 --- a/src/object/function_doc_signature.cpp +++ b/src/object/function_doc_signature.cpp @@ -114,19 +114,24 @@ namespace boost { namespace python { namespace objects { return res; } - const char * function_doc_signature_generator::py_type_str(const python::detail::signature_element &s) + str function_doc_signature_generator::py_type_str(const python::detail::signature_element &s) { if (s.basename==std::string("void")){ static const char * none = "None"; - return none; + return str(none); } PyTypeObject const * py_type = s.pytype_f?s.pytype_f():0; +#if PY_VERSION_HEX < 0x03030000 if ( py_type ) - return py_type->tp_name; + return str(py_type->tp_name); +#else + if ( py_type && (py_type->tp_flags & Py_TPFLAGS_HEAPTYPE) ) + return str(handle<>(borrowed(((PyHeapTypeObject*)(py_type))->ht_qualname))); +#endif else{ static const char * object = "object"; - return object; + return str(object); } } diff --git a/test/nested.cpp b/test/nested.cpp index de656d2b..b807c8bd 100644 --- a/test/nested.cpp +++ b/test/nested.cpp @@ -4,6 +4,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #include #include +#include #include #include #include "test_class.hpp" @@ -26,11 +27,13 @@ std::ostream& operator<<(std::ostream& s, Y const& x) return s << x.value(); } +void test_function(const X& x, const Y& y) {} BOOST_PYTHON_MODULE(nested_ext) { using namespace boost::python; + { // Establish X as the current scope. scope x_class = class_("X", init()) @@ -42,6 +45,10 @@ BOOST_PYTHON_MODULE(nested_ext) class_("Y", init()) .def(str(self)) ; + } + + // The generated docstring will use the fully-qualified name of Y + def("test_function", &test_function); } diff --git a/test/nested.py b/test/nested.py index 56f81e52..3d97208b 100644 --- a/test/nested.py +++ b/test/nested.py @@ -21,6 +21,9 @@ >>> X.Y.__name__ 'Y' + + >>> test_function.__doc__.strip().split('\\n')[0] + 'test_function( (X)arg1, (X.Y)arg2) -> None :' '''