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>
This commit is contained in:
Sergei Izmailov 2023-08-31 14:43:01 +09:00 committed by GitHub
parent e705fb5f27
commit db412e6e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -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");
}; };

View File

@ -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"
)