From 5194855900f0574106877646c60d302cc944a3b8 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Sun, 16 Jan 2022 18:05:46 +0300 Subject: [PATCH] Render `py::bool_` and `py::float_` without `_` in docstrings (#3622) * Render `py::bool_` as `bool` in docstrings * Render `py::float_` as `float` in docstrings --- include/pybind11/cast.h | 2 ++ tests/test_pytypes.cpp | 4 ++++ tests/test_pytypes.py | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 7930fb994..165102443 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -765,10 +765,12 @@ template struct is_holder_type struct handle_type_name { static constexpr auto name = const_name(); }; +template <> struct handle_type_name { static constexpr auto name = const_name("bool"); }; template <> struct handle_type_name { static constexpr auto name = const_name(PYBIND11_BYTES_NAME); }; template <> struct handle_type_name { static constexpr auto name = const_name("int"); }; template <> struct handle_type_name { static constexpr auto name = const_name("Iterable"); }; template <> struct handle_type_name { static constexpr auto name = const_name("Iterator"); }; +template <> struct handle_type_name { static constexpr auto name = const_name("float"); }; template <> struct handle_type_name { static constexpr auto name = const_name("None"); }; template <> struct handle_type_name { static constexpr auto name = const_name("*args"); }; template <> struct handle_type_name { static constexpr auto name = const_name("**kwargs"); }; diff --git a/tests/test_pytypes.cpp b/tests/test_pytypes.cpp index 9a1e91881..85cb98fcb 100644 --- a/tests/test_pytypes.cpp +++ b/tests/test_pytypes.cpp @@ -13,12 +13,16 @@ TEST_SUBMODULE(pytypes, m) { + // test_bool + m.def("get_bool", []{return py::bool_(false);}); // test_int m.def("get_int", []{return py::int_(0);}); // test_iterator m.def("get_iterator", []{return py::iterator();}); // test_iterable m.def("get_iterable", []{return py::iterable();}); + // test_float + m.def("get_float", []{return py::float_(0.0f);}); // test_list m.def("list_no_args", []() { return py::list{}; }); m.def("list_ssize_t", []() { return py::list{(py::ssize_t) 0}; }); diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 5215b79bc..2cd6c3f03 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -10,6 +10,10 @@ from pybind11_tests import debug_enabled from pybind11_tests import pytypes as m +def test_bool(doc): + assert doc(m.get_bool) == "get_bool() -> bool" + + def test_int(doc): assert doc(m.get_int) == "get_int() -> int" @@ -22,6 +26,10 @@ def test_iterable(doc): assert doc(m.get_iterable) == "get_iterable() -> Iterable" +def test_float(doc): + assert doc(m.get_float) == "get_float() -> float" + + def test_list(capture, doc): assert m.list_no_args() == [] assert m.list_ssize_t() == []