mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 04:22:16 +00:00
Emit qualfied names in docstrings
This commit is contained in:
committed by
Stefan Seefeld
parent
58b1a010bb
commit
7a3cc07042
@@ -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<function const*> flatten(function const *f);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
#include <boost/python/operators.hpp>
|
||||
#include <boost/python/scope.hpp>
|
||||
#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>("X", init<int>())
|
||||
@@ -42,6 +45,10 @@ BOOST_PYTHON_MODULE(nested_ext)
|
||||
class_<Y>("Y", init<int>())
|
||||
.def(str(self))
|
||||
;
|
||||
}
|
||||
|
||||
// The generated docstring will use the fully-qualified name of Y
|
||||
def("test_function", &test_function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
|
||||
>>> X.Y.__name__
|
||||
'Y'
|
||||
|
||||
>>> test_function.__doc__.strip().split('\\n')[0]
|
||||
'test_function( (X)arg1, (X.Y)arg2) -> None :'
|
||||
|
||||
'''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user