From 7861dcfabb78ac210b4c67c35a0d47fb67525a96 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Fri, 1 Sep 2023 10:10:11 +0900 Subject: [PATCH] fix: Render `py::object` as `Any` --- include/pybind11/cast.h | 4 ++++ tests/test_callbacks.py | 2 +- tests/test_factory_constructors.py | 4 ++-- tests/test_numpy_vectorize.py | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index d31cdfb02..a7f4dfc96 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -906,6 +906,10 @@ struct handle_type_name { static constexpr auto name = const_name("Callable"); }; template <> +struct handle_type_name { + static constexpr auto name = const_name("Any"); +}; +template <> struct handle_type_name { static constexpr auto name = handle_type_name::name; }; diff --git a/tests/test_callbacks.py b/tests/test_callbacks.py index 86c767455..9a2c5f899 100644 --- a/tests/test_callbacks.py +++ b/tests/test_callbacks.py @@ -221,5 +221,5 @@ def test_custom_func2(): def test_callback_docstring(): assert ( m.test_tuple_unpacking.__doc__.strip() - == "test_tuple_unpacking(arg0: Callable) -> object" + == "test_tuple_unpacking(arg0: Callable) -> Any" ) diff --git a/tests/test_factory_constructors.py b/tests/test_factory_constructors.py index a9004cbf6..acdb5728b 100644 --- a/tests/test_factory_constructors.py +++ b/tests/test_factory_constructors.py @@ -77,7 +77,7 @@ def test_init_factory_signature(msg): 1. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int) 2. m.factory_constructors.TestFactory1(arg0: str) 3. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.pointer_tag) - 4. m.factory_constructors.TestFactory1(arg0: object, arg1: int, arg2: object) + 4. m.factory_constructors.TestFactory1(arg0: Any, arg1: int, arg2: Any) Invoked with: 'invalid', 'constructor', 'arguments' """ @@ -95,7 +95,7 @@ def test_init_factory_signature(msg): 3. __init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.pointer_tag) -> None - 4. __init__(self: m.factory_constructors.TestFactory1, arg0: object, arg1: int, arg2: object) -> None + 4. __init__(self: m.factory_constructors.TestFactory1, arg0: Any, arg1: int, arg2: Any) -> None """ ) diff --git a/tests/test_numpy_vectorize.py b/tests/test_numpy_vectorize.py index f1e8b6254..3e2d82042 100644 --- a/tests/test_numpy_vectorize.py +++ b/tests/test_numpy_vectorize.py @@ -148,7 +148,7 @@ def test_docs(doc): assert ( doc(m.vectorized_func) == """ - vectorized_func(arg0: numpy.ndarray[numpy.int32], arg1: numpy.ndarray[numpy.float32], arg2: numpy.ndarray[numpy.float64]) -> object + vectorized_func(arg0: numpy.ndarray[numpy.int32], arg1: numpy.ndarray[numpy.float32], arg2: numpy.ndarray[numpy.float64]) -> Any """ ) @@ -218,7 +218,7 @@ def test_passthrough_arguments(doc): "arg6: numpy.ndarray[numpy.float64]", ] ) - + ") -> object" + + ") -> Any" ) b = np.array([[10, 20, 30]], dtype="float64")