Skip to content

Commit 7a3cc07

Browse files
jvansantenstefanseefeld
authored andcommitted
Emit qualfied names in docstrings
1 parent 58b1a01 commit 7a3cc07

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

include/boost/python/object/function_doc_signature.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace boost { namespace python { namespace objects {
1919

2020
class function_doc_signature_generator{
21-
static const char * py_type_str(const python::detail::signature_element &s);
21+
static str py_type_str(const python::detail::signature_element &s);
2222
static bool arity_cmp( function const *f1, function const *f2 );
2323
static bool are_seq_overloads( function const *f1, function const *f2 , bool check_docs);
2424
static std::vector<function const*> flatten(function const *f);

src/object/function_doc_signature.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,24 @@ namespace boost { namespace python { namespace objects {
114114
return res;
115115
}
116116

117-
const char * function_doc_signature_generator::py_type_str(const python::detail::signature_element &s)
117+
str function_doc_signature_generator::py_type_str(const python::detail::signature_element &s)
118118
{
119119
if (s.basename==std::string("void")){
120120
static const char * none = "None";
121-
return none;
121+
return str(none);
122122
}
123123

124124
PyTypeObject const * py_type = s.pytype_f?s.pytype_f():0;
125+
#if PY_VERSION_HEX < 0x03030000
125126
if ( py_type )
126-
return py_type->tp_name;
127+
return str(py_type->tp_name);
128+
#else
129+
if ( py_type && (py_type->tp_flags & Py_TPFLAGS_HEAPTYPE) )
130+
return str(handle<>(borrowed(((PyHeapTypeObject*)(py_type))->ht_qualname)));
131+
#endif
127132
else{
128133
static const char * object = "object";
129-
return object;
134+
return str(object);
130135
}
131136
}
132137

test/nested.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55
#include <boost/python/module.hpp>
66
#include <boost/python/class.hpp>
7+
#include <boost/python/def.hpp>
78
#include <boost/python/operators.hpp>
89
#include <boost/python/scope.hpp>
910
#include "test_class.hpp"
@@ -26,11 +27,13 @@ std::ostream& operator<<(std::ostream& s, Y const& x)
2627
return s << x.value();
2728
}
2829

30+
void test_function(const X& x, const Y& y) {}
2931

3032
BOOST_PYTHON_MODULE(nested_ext)
3133
{
3234
using namespace boost::python;
3335

36+
{
3437
// Establish X as the current scope.
3538
scope x_class
3639
= class_<X>("X", init<int>())
@@ -42,6 +45,10 @@ BOOST_PYTHON_MODULE(nested_ext)
4245
class_<Y>("Y", init<int>())
4346
.def(str(self))
4447
;
48+
}
49+
50+
// The generated docstring will use the fully-qualified name of Y
51+
def("test_function", &test_function);
4552
}
4653

4754

test/nested.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
2222
>>> X.Y.__name__
2323
'Y'
24+
25+
>>> test_function.__doc__.strip().split('\\n')[0]
26+
'test_function( (X)arg1, (X.Y)arg2) -> None :'
2427
2528
'''
2629

0 commit comments

Comments
 (0)