From d67afe450a64da55f9f66ef635d3ee543c3b89c7 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Fri, 1 Sep 2023 09:23:33 +0900 Subject: [PATCH 1/7] fix: Add capitalize render name of `py::buffer` and `py::sequence` --- include/pybind11/cast.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 8a4e2e6476..b05f6bbb0d 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -882,6 +882,10 @@ struct handle_type_name { static constexpr auto name = const_name(PYBIND11_BYTES_NAME); }; template <> +struct handle_type_name { + static constexpr auto name = const_name("Buffer"); +}; +template <> struct handle_type_name { static constexpr auto name = const_name("int"); }; @@ -906,6 +910,10 @@ struct handle_type_name { static constexpr auto name = const_name("None"); }; template <> +struct handle_type_name { + static constexpr auto name = const_name("Sequence"); +}; +template <> struct handle_type_name { static constexpr auto name = const_name("*args"); }; From b9893666c7621beadd7cf43c3dead2ba7ef06cf9 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Fri, 1 Sep 2023 09:23:59 +0900 Subject: [PATCH 2/7] fix: Render `py::handle` same way as `py::object` --- include/pybind11/cast.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index b05f6bbb0d..d31cdfb029 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 = handle_type_name::name; +}; +template <> struct handle_type_name { static constexpr auto name = const_name("None"); }; From d3d700df2b44e8913112d99bcfcc3a3cb7fb615e Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Fri, 1 Sep 2023 09:26:36 +0900 Subject: [PATCH 3/7] tests: Fix tests `handle` -> `object` --- tests/test_factory_constructors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_factory_constructors.py b/tests/test_factory_constructors.py index 04df80260d..a9004cbf67 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: handle, arg1: int, arg2: handle) + 4. m.factory_constructors.TestFactory1(arg0: object, arg1: int, arg2: object) 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: handle, arg1: int, arg2: handle) -> None + 4. __init__(self: m.factory_constructors.TestFactory1, arg0: object, arg1: int, arg2: object) -> None """ ) From 46a7dd4b174dd3bdd37cde67cfdf444d0a72e54d Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Fri, 1 Sep 2023 09:38:40 +0900 Subject: [PATCH 4/7] tests: Test capitaliation of `py::sequence` and `py::buffer` --- tests/test_buffers.py | 4 ++++ tests/test_sequences_and_iterators.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/test_buffers.py b/tests/test_buffers.py index 63d9d869fd..0e70b3a065 100644 --- a/tests/test_buffers.py +++ b/tests/test_buffers.py @@ -219,3 +219,7 @@ def test_ctypes_from_buffer(): assert cinfo.shape == pyinfo.shape assert cinfo.strides == pyinfo.strides assert not cinfo.readonly + + +def test_buffer_docstring(): + assert m.get_buffer_info.__doc__.strip() == "get_buffer_info(arg0: Buffer) -> pybind11_tests.buffers.buffer_info" diff --git a/tests/test_sequences_and_iterators.py b/tests/test_sequences_and_iterators.py index dc129f2bff..acbe9d8983 100644 --- a/tests/test_sequences_and_iterators.py +++ b/tests/test_sequences_and_iterators.py @@ -171,6 +171,10 @@ def __len__(self): assert m.sequence_length("hello") == 5 +def test_sequence_doc(): + assert m.sequence_length.__doc__.strip() == "sequence_length(arg0: Sequence) -> int" + + def test_map_iterator(): sm = m.StringMap({"hi": "bye", "black": "white"}) assert sm["hi"] == "bye" From d8b91c68ebc838d61e6d2d9da7af695a5ff6a992 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 00:45:32 +0000 Subject: [PATCH 5/7] style: pre-commit fixes --- tests/test_buffers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_buffers.py b/tests/test_buffers.py index 0e70b3a065..5d33625ba4 100644 --- a/tests/test_buffers.py +++ b/tests/test_buffers.py @@ -222,4 +222,7 @@ def test_ctypes_from_buffer(): def test_buffer_docstring(): - assert m.get_buffer_info.__doc__.strip() == "get_buffer_info(arg0: Buffer) -> pybind11_tests.buffers.buffer_info" + assert ( + m.get_buffer_info.__doc__.strip() + == "get_buffer_info(arg0: Buffer) -> pybind11_tests.buffers.buffer_info" + ) From 7861dcfabb78ac210b4c67c35a0d47fb67525a96 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Fri, 1 Sep 2023 10:10:11 +0900 Subject: [PATCH 6/7] 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 d31cdfb029..a7f4dfc963 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 86c7674555..9a2c5f8996 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 a9004cbf67..acdb5728bc 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 f1e8b62540..3e2d820421 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") From 7e2def4c4cba4a213342cff093e475da961d5be4 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Mon, 11 Sep 2023 15:26:35 +0900 Subject: [PATCH 7/7] Revert "fix: Render `py::object` as `Any`" This reverts commit 7861dcfabb78ac210b4c67c35a0d47fb67525a96. --- 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, 5 insertions(+), 9 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index a7f4dfc963..d31cdfb029 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -906,10 +906,6 @@ 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 9a2c5f8996..86c7674555 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) -> Any" + == "test_tuple_unpacking(arg0: Callable) -> object" ) diff --git a/tests/test_factory_constructors.py b/tests/test_factory_constructors.py index acdb5728bc..a9004cbf67 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: Any, arg1: int, arg2: Any) + 4. m.factory_constructors.TestFactory1(arg0: object, arg1: int, arg2: object) 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: Any, arg1: int, arg2: Any) -> None + 4. __init__(self: m.factory_constructors.TestFactory1, arg0: object, arg1: int, arg2: object) -> None """ ) diff --git a/tests/test_numpy_vectorize.py b/tests/test_numpy_vectorize.py index 3e2d820421..f1e8b62540 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]) -> Any + vectorized_func(arg0: numpy.ndarray[numpy.int32], arg1: numpy.ndarray[numpy.float32], arg2: numpy.ndarray[numpy.float64]) -> object """ ) @@ -218,7 +218,7 @@ def test_passthrough_arguments(doc): "arg6: numpy.ndarray[numpy.float64]", ] ) - + ") -> Any" + + ") -> object" ) b = np.array([[10, 20, 30]], dtype="float64")