Skip to content

Commit 3358788

Browse files
committed
Avoid duplicating all signatures. Also get rid of "generic" signature.
1 parent 62c7a35 commit 3358788

File tree

4 files changed

+8
-43
lines changed

4 files changed

+8
-43
lines changed

docs/advanced/misc.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,7 @@ The above example would produce the following docstring:
389389
>>> help(example.add)
390390
391391
add(...)
392-
| add(arg0: int, arg1: int) -> int
393-
| add(arg0: float, arg1: float) -> float
394-
| Overloaded function.
392+
| Overloaded function:
395393
|
396394
| 1. add(arg0: int, arg1: int) -> int
397395
|
@@ -403,7 +401,6 @@ The above example would produce the following docstring:
403401
404402
Calling ``options.disable_function_signatures()`` as shown previously
405403
will cause the docstrings of overloaded functions to be generated without the section headings.
406-
The prepended overload signatures will remain:
407404

408405
.. code-block:: cpp
409406
@@ -425,9 +422,6 @@ The above example would produce the following docstring:
425422
426423
>>> help(example.add)
427424
add(...)
428-
| add(arg0: int, arg1: int) -> int
429-
| add(arg0: float, arg1: float) -> float
430-
| add(arg0: None, arg1: None) -> None
431425
| A function which adds two numbers.
432426
|
433427
| Internally, a simple addition is performed.

include/pybind11/pybind11.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -612,15 +612,8 @@ class cpp_function : public function {
612612
int index = 0;
613613
/* Create a nice pydoc rec including all signatures and
614614
docstrings of the functions in the overload chain */
615-
if (chain) {
616-
for (auto *it = chain_start; it != nullptr; it = it->next) {
617-
signatures += rec->name;
618-
signatures += it->signature;
619-
signatures += "\n";
620-
}
621-
if (options::show_function_signatures()) {
622-
signatures += "Overloaded function.\n\n";
623-
}
615+
if (chain && options::show_function_signatures()) {
616+
signatures += "Overloaded function:\n\n";
624617
}
625618
// Then specific overload signatures
626619
bool first_user_def = true;

tests/test_docstring_options.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,23 @@ def test_docstring_options():
1010
assert m.test_function2.__doc__ == "A custom docstring"
1111

1212
# docstring specified on just the first overload definition:
13-
assert m.test_overloaded1.__doc__ == (
14-
"test_overloaded1(i: int) -> None\n"
15-
"test_overloaded1(d: float) -> None\n"
16-
"Overload docstring"
17-
)
13+
assert m.test_overloaded1.__doc__ == "Overload docstring"
1814

1915
# docstring on both overloads:
20-
assert m.test_overloaded2.__doc__ == (
21-
"test_overloaded2(i: int) -> None\n"
22-
"test_overloaded2(d: float) -> None\n"
23-
"overload docstring 1\n"
24-
"overload docstring 2"
25-
)
16+
assert m.test_overloaded2.__doc__ == "overload docstring 1\noverload docstring 2"
2617

2718
# docstring on only second overload:
28-
assert m.test_overloaded3.__doc__ == (
29-
"test_overloaded3(i: int) -> None\n"
30-
"test_overloaded3(d: float) -> None\n"
31-
"Overload docstr"
32-
)
19+
assert m.test_overloaded3.__doc__ == "Overload docstr"
3320

3421
# Check overload configuration behaviour matches the documentation
3522
assert m.test_overloaded4.__doc__ == (
36-
"test_overloaded4(arg0: int, arg1: int) -> int\n"
37-
"test_overloaded4(arg0: float, arg1: float) -> float\n"
38-
"test_overloaded4(arg0: None, arg1: None) -> None\n"
3923
"A function which adds two numbers.\n\n"
4024
"Internally, a simple addition is performed.\n"
4125
"Both numbers can be None, and None will be returned."
4226
)
4327

4428
assert m.test_overloaded5.__doc__ == (
45-
"test_overloaded5(arg0: int, arg1: int) -> int\n"
46-
"test_overloaded5(arg0: float, arg1: float) -> float\n"
47-
"Overloaded function.\n"
29+
"Overloaded function:\n"
4830
"\n"
4931
"1. test_overloaded5(arg0: int, arg1: int) -> int\n"
5032
"\n"

tests/test_factory_constructors.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ def test_init_factory_signature(msg):
8888
assert (
8989
msg(m.TestFactory1.__init__.__doc__)
9090
== """
91-
__init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int) -> None
92-
__init__(self: m.factory_constructors.TestFactory1, arg0: str) -> None
93-
__init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.pointer_tag) -> None
94-
__init__(self: m.factory_constructors.TestFactory1, arg0: object, arg1: int, arg2: object) -> None
95-
Overloaded function.
91+
Overloaded function:
9692
9793
1. __init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int) -> None
9894

0 commit comments

Comments
 (0)