Skip to content

Commit db412e6

Browse files
fix: Render py::function as Callable (#4829)
* fix: Render `py::function` as `Callable` * style: pre-commit fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e705fb5 commit db412e6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

include/pybind11/cast.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,10 @@ struct handle_type_name<float_> {
898898
static constexpr auto name = const_name("float");
899899
};
900900
template <>
901+
struct handle_type_name<function> {
902+
static constexpr auto name = const_name("Callable");
903+
};
904+
template <>
901905
struct handle_type_name<none> {
902906
static constexpr auto name = const_name("None");
903907
};

tests/test_callbacks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,10 @@ def test_custom_func():
216216
def test_custom_func2():
217217
assert m.custom_function2(3) == 27
218218
assert m.roundtrip(m.custom_function2)(3) == 27
219+
220+
221+
def test_callback_docstring():
222+
assert (
223+
m.test_tuple_unpacking.__doc__.strip()
224+
== "test_tuple_unpacking(arg0: Callable) -> object"
225+
)

0 commit comments

Comments
 (0)