From d1694d9ac5368512c8ebd2ca88deb51995f31f6b Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 14 Nov 2023 22:28:38 -0800 Subject: [PATCH] Use locally defined bindings to avoid dependency on test_stl. --- tests/test_cases_for_stubgen.cpp | 16 +++++++++++++--- tests/test_cases_for_stubgen.py | 9 ++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/test_cases_for_stubgen.cpp b/tests/test_cases_for_stubgen.cpp index 43a87e0be..e24f2ee53 100644 --- a/tests/test_cases_for_stubgen.cpp +++ b/tests/test_cases_for_stubgen.cpp @@ -1,6 +1,8 @@ +#include "pybind11/stl.h" #include "pybind11/stl_bind.h" #include "pybind11_tests.h" +#include #include namespace test_cases_for_stubgen { @@ -41,6 +43,11 @@ struct type_caster : test_cases_for_stubgen::m } // namespace detail } // namespace pybind11 +PYBIND11_MAKE_OPAQUE(std::map); +PYBIND11_MAKE_OPAQUE(std::map); +PYBIND11_MAKE_OPAQUE(std::map); +PYBIND11_MAKE_OPAQUE(std::map); + TEST_SUBMODULE(cases_for_stubgen, m) { using UserType = test_cases_for_stubgen::UserType; @@ -50,7 +57,7 @@ TEST_SUBMODULE(cases_for_stubgen, m) { py::bind_map>(m, "MapIntUserType"); py::bind_map>(m, "MapUserTypeInt"); -#define MAP_TYPE(MapTypePythonName, ...) \ +#define LOCAL_HELPER(MapTypePythonName, ...) \ py::class_<__VA_ARGS__>(m, MapTypePythonName) \ .def( \ "keys", \ @@ -65,8 +72,11 @@ TEST_SUBMODULE(cases_for_stubgen, m) { [](const __VA_ARGS__ &v) { return py::make_iterator(v.begin(), v.end()); }, \ py::keep_alive<0, 1>()) - MAP_TYPE("MapFloatUserType", std::map); - MAP_TYPE("MapUserTypeFloat", std::map); + LOCAL_HELPER("MapFloatUserType", std::map); + LOCAL_HELPER("MapUserTypeFloat", std::map); #undef MAP_TYPE + + m.def("pass_std_array_int_2", [](const std::array &) {}); + m.def("return_std_array_int_3", []() { return std::array{{1, 2, 3}}; }); } diff --git a/tests/test_cases_for_stubgen.py b/tests/test_cases_for_stubgen.py index 24508ac21..7505cfa79 100644 --- a/tests/test_cases_for_stubgen.py +++ b/tests/test_cases_for_stubgen.py @@ -1,7 +1,6 @@ import pytest from pybind11_tests import cases_for_stubgen as m -from pybind11_tests import stl as test_stl @pytest.mark.parametrize( @@ -64,12 +63,12 @@ from pybind11_tests import stl as test_stl '__iter__(self: pybind11_tests.cases_for_stubgen.MapUserTypeFloat) -> Iterator[tuple[Annotated[Any, "test_cases_for_stubgen::UserType"], float]]\n', ), ( - test_stl.cast_array.__doc__, - "cast_array() -> Annotated[list[int], FixedSize(2)]\n", + m.pass_std_array_int_2.__doc__, + "pass_std_array_int_2(arg0: Annotated[list[int], FixedSize(2)]) -> None\n", ), ( - test_stl.load_array.__doc__, - "load_array(arg0: Annotated[list[int], FixedSize(2)]) -> bool\n", + m.return_std_array_int_3.__doc__, + "return_std_array_int_3() -> Annotated[list[int], FixedSize(3)]\n", ), ], )