@@ -114,28 +114,47 @@ namespace boost { namespace python { namespace objects {
114114 return res;
115115 }
116116
117- str function_doc_signature_generator::py_type_str (const python::detail::signature_element &s)
117+ static str get_qualname (const PyTypeObject *py_type)
118+ {
119+ # if PY_VERSION_HEX >= 0x03030000
120+ if ( py_type->tp_flags & Py_TPFLAGS_HEAPTYPE )
121+ return str (handle<>(borrowed (((PyHeapTypeObject*)(py_type))->ht_qualname )));
122+ # endif
123+ return str (py_type->tp_name );
124+ }
125+
126+ str function_doc_signature_generator::py_type_str (const python::detail::signature_element &s, const object ¤t_module_name)
118127 {
119128 if (s.basename ==std::string (" void" )){
120129 static const char * none = " None" ;
121130 return str (none);
122131 }
123132
124133 PyTypeObject const * py_type = s.pytype_f ?s.pytype_f ():0 ;
125- #if PY_VERSION_HEX < 0x03030000
126- if ( py_type )
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
132- else {
134+ if ( py_type ) {
135+ str name (get_qualname (py_type));
136+ if ( py_type->tp_flags & Py_TPFLAGS_HEAPTYPE ) {
137+ // Qualify the type name if it is defined in a different module.
138+ PyObject *type_module_name = PyDict_GetItemString (py_type->tp_dict , " __module__" );
139+ if (
140+ type_module_name
141+ && PyObject_RichCompareBool (
142+ type_module_name,
143+ current_module_name.ptr (),
144+ Py_NE
145+ ) != 0
146+ ) {
147+ return str (" %s.%s" % make_tuple (handle<>(borrowed (type_module_name)), name));
148+ }
149+ }
150+ return name;
151+ } else {
133152 static const char * object = " object" ;
134153 return str (object);
135154 }
136155 }
137156
138- str function_doc_signature_generator::parameter_string (py_function const &f, size_t n, object arg_names, bool cpp_types)
157+ str function_doc_signature_generator::parameter_string (py_function const &f, size_t n, object arg_names, const object& current_module_name, bool cpp_types)
139158 {
140159 str param;
141160
@@ -161,12 +180,12 @@ namespace boost { namespace python { namespace objects {
161180 {
162181 object kv;
163182 if ( arg_names && (kv = arg_names[n-1 ]) )
164- param = str ( " (%s)%s" % make_tuple (py_type_str (s[n]),kv[0 ]) );
183+ param = str ( " (%s)%s" % make_tuple (py_type_str (s[n], current_module_name ),kv[0 ]) );
165184 else
166- param = str (" (%s)%s%d" % make_tuple (py_type_str (s[n])," arg" , n) );
185+ param = str (" (%s)%s%d" % make_tuple (py_type_str (s[n], current_module_name )," arg" , n) );
167186 }
168187 else // we are processing the return type
169- param = py_type_str (f.get_return_type ());
188+ param = py_type_str (f.get_return_type (), current_module_name );
170189 }
171190
172191 // an argument - check for default value and append it
@@ -204,7 +223,7 @@ namespace boost { namespace python { namespace objects {
204223 str param;
205224
206225 formal_params.append (
207- parameter_string (impl, n, f->m_arg_names , cpp_types)
226+ parameter_string (impl, n, f->m_arg_names , f-> get_module (), cpp_types)
208227 );
209228
210229 // find all the arguments with default values preceeding the arity-n_overloads
0 commit comments