Avoid duplicating all signatures. Also get rid of "generic" signature.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-08-22 20:58:00 -07:00
parent 62c7a35aba
commit 335878892f
4 changed files with 8 additions and 43 deletions

View File

@ -389,9 +389,7 @@ The above example would produce the following docstring:
>>> help(example.add)
add(...)
| add(arg0: int, arg1: int) -> int
| add(arg0: float, arg1: float) -> float
| Overloaded function.
| Overloaded function:
|
| 1. add(arg0: int, arg1: int) -> int
|
@ -403,7 +401,6 @@ The above example would produce the following docstring:
Calling ``options.disable_function_signatures()`` as shown previously
will cause the docstrings of overloaded functions to be generated without the section headings.
The prepended overload signatures will remain:
.. code-block:: cpp
@ -425,9 +422,6 @@ The above example would produce the following docstring:
>>> help(example.add)
add(...)
| add(arg0: int, arg1: int) -> int
| add(arg0: float, arg1: float) -> float
| add(arg0: None, arg1: None) -> None
| A function which adds two numbers.
|
| Internally, a simple addition is performed.

View File

@ -612,15 +612,8 @@ protected:
int index = 0;
/* Create a nice pydoc rec including all signatures and
docstrings of the functions in the overload chain */
if (chain) {
for (auto *it = chain_start; it != nullptr; it = it->next) {
signatures += rec->name;
signatures += it->signature;
signatures += "\n";
}
if (options::show_function_signatures()) {
signatures += "Overloaded function.\n\n";
}
if (chain && options::show_function_signatures()) {
signatures += "Overloaded function:\n\n";
}
// Then specific overload signatures
bool first_user_def = true;

View File

@ -10,41 +10,23 @@ def test_docstring_options():
assert m.test_function2.__doc__ == "A custom docstring"
# docstring specified on just the first overload definition:
assert m.test_overloaded1.__doc__ == (
"test_overloaded1(i: int) -> None\n"
"test_overloaded1(d: float) -> None\n"
"Overload docstring"
)
assert m.test_overloaded1.__doc__ == "Overload docstring"
# docstring on both overloads:
assert m.test_overloaded2.__doc__ == (
"test_overloaded2(i: int) -> None\n"
"test_overloaded2(d: float) -> None\n"
"overload docstring 1\n"
"overload docstring 2"
)
assert m.test_overloaded2.__doc__ == "overload docstring 1\noverload docstring 2"
# docstring on only second overload:
assert m.test_overloaded3.__doc__ == (
"test_overloaded3(i: int) -> None\n"
"test_overloaded3(d: float) -> None\n"
"Overload docstr"
)
assert m.test_overloaded3.__doc__ == "Overload docstr"
# Check overload configuration behaviour matches the documentation
assert m.test_overloaded4.__doc__ == (
"test_overloaded4(arg0: int, arg1: int) -> int\n"
"test_overloaded4(arg0: float, arg1: float) -> float\n"
"test_overloaded4(arg0: None, arg1: None) -> None\n"
"A function which adds two numbers.\n\n"
"Internally, a simple addition is performed.\n"
"Both numbers can be None, and None will be returned."
)
assert m.test_overloaded5.__doc__ == (
"test_overloaded5(arg0: int, arg1: int) -> int\n"
"test_overloaded5(arg0: float, arg1: float) -> float\n"
"Overloaded function.\n"
"Overloaded function:\n"
"\n"
"1. test_overloaded5(arg0: int, arg1: int) -> int\n"
"\n"

View File

@ -88,11 +88,7 @@ def test_init_factory_signature(msg):
assert (
msg(m.TestFactory1.__init__.__doc__)
== """
__init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int) -> None
__init__(self: m.factory_constructors.TestFactory1, arg0: str) -> None
__init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.pointer_tag) -> None
__init__(self: m.factory_constructors.TestFactory1, arg0: object, arg1: int, arg2: object) -> None
Overloaded function.
Overloaded function:
1. __init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int) -> None