GeezerVison is showing github.com — Emit qualfied names in docstrings · boostorg/python@7a3cc07
File tree
Expand file treeCollapse file tree
Open diff view settings
include/boost/python/object
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: include/boost/python/object/function_doc_signature.hpp +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
18 | 18 | namespace boost { namespace python { namespace objects { |
19 | 19 |
|
20 | 20 | 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); |
22 | 22 | static bool arity_cmp( function const *f1, function const *f2 ); |
23 | 23 | static bool are_seq_overloads( function const *f1, function const *f2 , bool check_docs); |
24 | 24 | static std::vector<function const*> flatten(function const *f); |
|
Collapse file
Copy file name to clipboardExpand all lines: src/object/function_doc_signature.cpp +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -114,19 +114,24 @@ namespace boost { namespace python { namespace objects { |
114 | 114 | return res; |
115 | 115 | } |
116 | 116 |
|
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) |
118 | 118 | { |
119 | 119 | if (s.basename==std::string("void")){ |
120 | 120 | static const char * none = "None"; |
121 | | - return none; |
| 121 | + return str(none); |
122 | 122 | } |
123 | 123 |
|
124 | 124 | PyTypeObject const * py_type = s.pytype_f?s.pytype_f():0; |
| 125 | +#if PY_VERSION_HEX < 0x03030000 |
125 | 126 | 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 |
127 | 132 | else{ |
128 | 133 | static const char * object = "object"; |
129 | | - return object; |
| 134 | + return str(object); |
130 | 135 | } |
131 | 136 | } |
132 | 137 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: test/nested.cpp +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
4 | 4 | // http://www.boost.org/LICENSE_1_0.txt) |
5 | 5 | #include <boost/python/module.hpp> |
6 | 6 | #include <boost/python/class.hpp> |
| 7 | +#include <boost/python/def.hpp> |
7 | 8 | #include <boost/python/operators.hpp> |
8 | 9 | #include <boost/python/scope.hpp> |
9 | 10 | #include "test_class.hpp" |
@@ -26,11 +27,13 @@ std::ostream& operator<<(std::ostream& s, Y const& x) |
26 | 27 | return s << x.value(); |
27 | 28 | } |
28 | 29 |
|
| 30 | +void test_function(const X& x, const Y& y) {} |
29 | 31 |
|
30 | 32 | BOOST_PYTHON_MODULE(nested_ext) |
31 | 33 | { |
32 | 34 | using namespace boost::python; |
33 | 35 |
|
| 36 | + { |
34 | 37 | // Establish X as the current scope. |
35 | 38 | scope x_class |
36 | 39 | = class_<X>("X", init<int>()) |
@@ -42,6 +45,10 @@ BOOST_PYTHON_MODULE(nested_ext) |
42 | 45 | class_<Y>("Y", init<int>()) |
43 | 46 | .def(str(self)) |
44 | 47 | ; |
| 48 | + } |
| 49 | + |
| 50 | + // The generated docstring will use the fully-qualified name of Y |
| 51 | + def("test_function", &test_function); |
45 | 52 | } |
46 | 53 |
|
47 | 54 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: test/nested.py +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
21 | 21 | |
22 | 22 | >>> X.Y.__name__ |
23 | 23 | 'Y' |
| 24 | +
|
| 25 | + >>> test_function.__doc__.strip().split('\\n')[0] |
| 26 | + 'test_function( (X)arg1, (X.Y)arg2) -> None :' |
24 | 27 | |
25 | 28 | ''' |
26 | 29 |
|
|