diff --git a/docs/advanced/misc.rst b/docs/advanced/misc.rst index 8ae90db40..470a376c5 100644 --- a/docs/advanced/misc.rst +++ b/docs/advanced/misc.rst @@ -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. diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index a5856ea8e..275813482 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -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; diff --git a/tests/test_docstring_options.py b/tests/test_docstring_options.py index b27057c43..91982c7bd 100644 --- a/tests/test_docstring_options.py +++ b/tests/test_docstring_options.py @@ -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" diff --git a/tests/test_factory_constructors.py b/tests/test_factory_constructors.py index 92e32d1ec..bf443d523 100644 --- a/tests/test_factory_constructors.py +++ b/tests/test_factory_constructors.py @@ -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