@@ -250,6 +250,7 @@ class cpp_function : public function {
250
250
/* Generate a proper function signature */
251
251
std::string signature;
252
252
size_t type_index = 0 , arg_index = 0 ;
253
+ std::string self_type (" object" );
253
254
for (auto *pc = text; *pc != ' \0 ' ; ++pc) {
254
255
const auto c = *pc;
255
256
@@ -279,9 +280,13 @@ class cpp_function : public function {
279
280
pybind11_fail (" Internal error while parsing type signature (1)" );
280
281
if (auto tinfo = detail::get_type_info (*t)) {
281
282
handle th ((PyObject *) tinfo->type );
282
- signature + =
283
+ std::string tname =
283
284
th.attr (" __module__" ).cast <std::string>() + " ." +
284
285
th.attr (" __qualname__" ).cast <std::string>(); // Python 3.3+, but we backport it to earlier versions
286
+ signature += tname;
287
+ if (arg_index == 0 && rec->is_method ) {
288
+ self_type = tname;
289
+ }
285
290
} else if (rec->is_new_style_constructor && arg_index == 0 ) {
286
291
// A new-style `__init__` takes `self` as `value_and_holder`.
287
292
// Rewrite it to the proper class type.
@@ -292,6 +297,9 @@ class cpp_function : public function {
292
297
std::string tname (t->name ());
293
298
detail::clean_type_id (tname);
294
299
signature += tname;
300
+ if (arg_index == 0 && rec->is_method ) {
301
+ self_type = tname;
302
+ }
295
303
}
296
304
} else {
297
305
signature += c;
@@ -377,9 +385,10 @@ class cpp_function : public function {
377
385
378
386
std::string signatures;
379
387
int index = 0 ;
388
+ const bool has_overloads = (chain || rec->is_operator );
380
389
/* Create a nice pydoc rec including all signatures and
381
390
docstrings of the functions in the overload chain */
382
- if (chain && options::show_function_signatures ()) {
391
+ if (has_overloads && options::show_function_signatures ()) {
383
392
// First a generic signature
384
393
signatures += rec->name ;
385
394
signatures += " (*args, **kwargs)\n " ;
@@ -390,7 +399,7 @@ class cpp_function : public function {
390
399
for (auto it = chain_start; it != nullptr ; it = it->next ) {
391
400
if (options::show_function_signatures ()) {
392
401
if (index > 0 ) signatures += " \n " ;
393
- if (chain )
402
+ if (has_overloads )
394
403
signatures += std::to_string (++index ) + " . " ;
395
404
signatures += rec->name ;
396
405
signatures += it->signature ;
@@ -408,6 +417,16 @@ class cpp_function : public function {
408
417
if (options::show_function_signatures ()) signatures += " \n " ;
409
418
}
410
419
}
420
+ if (rec->is_operator ) {
421
+ signatures += " \n " ;
422
+ signatures += std::to_string (++index ) + " . " ;
423
+ signatures += rec->name ;
424
+ signatures += " (" ;
425
+ if (rec->is_method ) {
426
+ signatures += " self: " + self_type + " , " ;
427
+ }
428
+ signatures += " *args, **kwargs) -> NotImplemented\n " ;
429
+ }
411
430
412
431
/* Install docstring */
413
432
PyCFunctionObject *func = (PyCFunctionObject *) m_ptr;
0 commit comments