Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[smart_holder] Alternative to #2621 #5329

Draft
wants to merge 3 commits into
base: smart_holder
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Avoid duplicating all signatures. Also get rid of "generic" signature.
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Aug 23, 2024
commit 335878892fa22da6114dddfc15901bf032b08311
8 changes: 1 addition & 7 deletions docs/advanced/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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

Expand All @@ -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.
Expand Down
11 changes: 2 additions & 9 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,8 @@ class cpp_function : public function {
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;
Expand Down
26 changes: 4 additions & 22 deletions tests/test_docstring_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 1 addition & 5 deletions tests/test_factory_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down