@@ -114,28 +114,47 @@ namespace boost { namespace python { namespace objects {
114
114
return res;
115
115
}
116
116
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)
118
127
{
119
128
if (s.basename ==std::string (" void" )){
120
129
static const char * none = " None" ;
121
130
return str (none);
122
131
}
123
132
124
133
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 {
133
152
static const char * object = " object" ;
134
153
return str (object);
135
154
}
136
155
}
137
156
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)
139
158
{
140
159
str param;
141
160
@@ -161,12 +180,12 @@ namespace boost { namespace python { namespace objects {
161
180
{
162
181
object kv;
163
182
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 ]) );
165
184
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) );
167
186
}
168
187
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 );
170
189
}
171
190
172
191
// an argument - check for default value and append it
@@ -204,7 +223,7 @@ namespace boost { namespace python { namespace objects {
204
223
str param;
205
224
206
225
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)
208
227
);
209
228
210
229
// find all the arguments with default values preceeding the arity-n_overloads
0 commit comments