@@ -257,6 +257,7 @@ class cpp_function : public function {
257
257
/* Generate a proper function signature */
258
258
std::string signature;
259
259
size_t type_index = 0 , arg_index = 0 ;
260
+ std::string self_type (" object" );
260
261
for (auto *pc = text; *pc != ' \0 ' ; ++pc) {
261
262
const auto c = *pc;
262
263
@@ -293,9 +294,13 @@ class cpp_function : public function {
293
294
pybind11_fail (" Internal error while parsing type signature (1)" );
294
295
if (auto tinfo = detail::get_type_info (*t)) {
295
296
handle th ((PyObject *) tinfo->type );
296
- signature + =
297
+ std::string tname =
297
298
th.attr (" __module__" ).cast <std::string>() + " ." +
298
299
th.attr (" __qualname__" ).cast <std::string>(); // Python 3.3+, but we backport it to earlier versions
300
+ signature += tname;
301
+ if (arg_index == 0 && rec->is_method ) {
302
+ self_type = tname;
303
+ }
299
304
} else if (rec->is_new_style_constructor && arg_index == 0 ) {
300
305
// A new-style `__init__` takes `self` as `value_and_holder`.
301
306
// Rewrite it to the proper class type.
@@ -306,6 +311,9 @@ class cpp_function : public function {
306
311
std::string tname (t->name ());
307
312
detail::clean_type_id (tname);
308
313
signature += tname;
314
+ if (arg_index == 0 && rec->is_method ) {
315
+ self_type = tname;
316
+ }
309
317
}
310
318
} else {
311
319
signature += c;
@@ -404,9 +412,10 @@ class cpp_function : public function {
404
412
405
413
std::string signatures;
406
414
int index = 0 ;
415
+ const bool has_overloads = (chain || rec->is_operator );
407
416
/* Create a nice pydoc rec including all signatures and
408
417
docstrings of the functions in the overload chain */
409
- if (chain && options::show_function_signatures ()) {
418
+ if (has_overloads && options::show_function_signatures ()) {
410
419
// First a generic signature
411
420
signatures += rec->name ;
412
421
signatures += " (*args, **kwargs)\n " ;
@@ -417,7 +426,7 @@ class cpp_function : public function {
417
426
for (auto it = chain_start; it != nullptr ; it = it->next ) {
418
427
if (options::show_function_signatures ()) {
419
428
if (index > 0 ) signatures += " \n " ;
420
- if (chain )
429
+ if (has_overloads )
421
430
signatures += std::to_string (++index ) + " . " ;
422
431
signatures += rec->name ;
423
432
signatures += it->signature ;
@@ -435,6 +444,16 @@ class cpp_function : public function {
435
444
if (options::show_function_signatures ()) signatures += " \n " ;
436
445
}
437
446
}
447
+ if (rec->is_operator ) {
448
+ signatures += " \n " ;
449
+ signatures += std::to_string (++index ) + " . " ;
450
+ signatures += rec->name ;
451
+ signatures += " (" ;
452
+ if (rec->is_method ) {
453
+ signatures += " self: " + self_type + " , " ;
454
+ }
455
+ signatures += " *args, **kwargs) -> NotImplemented\n " ;
456
+ }
438
457
439
458
/* Install docstring */
440
459
auto *func = (PyCFunctionObject *) m_ptr;
0 commit comments