Commit db412e6e by Sergei Izmailov Committed by GitHub

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>
parent e705fb5f
...@@ -898,6 +898,10 @@ struct handle_type_name<float_> { ...@@ -898,6 +898,10 @@ struct handle_type_name<float_> {
static constexpr auto name = const_name("float"); static constexpr auto name = const_name("float");
}; };
template <> template <>
struct handle_type_name<function> {
static constexpr auto name = const_name("Callable");
};
template <>
struct handle_type_name<none> { struct handle_type_name<none> {
static constexpr auto name = const_name("None"); static constexpr auto name = const_name("None");
}; };
......
...@@ -216,3 +216,10 @@ def test_custom_func(): ...@@ -216,3 +216,10 @@ def test_custom_func():
def test_custom_func2(): def test_custom_func2():
assert m.custom_function2(3) == 27 assert m.custom_function2(3) == 27
assert m.roundtrip(m.custom_function2)(3) == 27 assert m.roundtrip(m.custom_function2)(3) == 27
def test_callback_docstring():
assert (
m.test_tuple_unpacking.__doc__.strip()
== "test_tuple_unpacking(arg0: Callable) -> object"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment