Skip to content

Commit 5194855

Browse files
authored
Render py::bool_ and py::float_ without _ in docstrings (#3622)
* Render `py::bool_` as `bool` in docstrings * Render `py::float_` as `float` in docstrings
1 parent 7e7c558 commit 5194855

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

include/pybind11/cast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,12 @@ template <typename base, typename deleter> struct is_holder_type<base, std::uniq
765765
std::true_type {};
766766

767767
template <typename T> struct handle_type_name { static constexpr auto name = const_name<T>(); };
768+
template <> struct handle_type_name<bool_> { static constexpr auto name = const_name("bool"); };
768769
template <> struct handle_type_name<bytes> { static constexpr auto name = const_name(PYBIND11_BYTES_NAME); };
769770
template <> struct handle_type_name<int_> { static constexpr auto name = const_name("int"); };
770771
template <> struct handle_type_name<iterable> { static constexpr auto name = const_name("Iterable"); };
771772
template <> struct handle_type_name<iterator> { static constexpr auto name = const_name("Iterator"); };
773+
template <> struct handle_type_name<float_> { static constexpr auto name = const_name("float"); };
772774
template <> struct handle_type_name<none> { static constexpr auto name = const_name("None"); };
773775
template <> struct handle_type_name<args> { static constexpr auto name = const_name("*args"); };
774776
template <> struct handle_type_name<kwargs> { static constexpr auto name = const_name("**kwargs"); };

tests/test_pytypes.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313

1414

1515
TEST_SUBMODULE(pytypes, m) {
16+
// test_bool
17+
m.def("get_bool", []{return py::bool_(false);});
1618
// test_int
1719
m.def("get_int", []{return py::int_(0);});
1820
// test_iterator
1921
m.def("get_iterator", []{return py::iterator();});
2022
// test_iterable
2123
m.def("get_iterable", []{return py::iterable();});
24+
// test_float
25+
m.def("get_float", []{return py::float_(0.0f);});
2226
// test_list
2327
m.def("list_no_args", []() { return py::list{}; });
2428
m.def("list_ssize_t", []() { return py::list{(py::ssize_t) 0}; });

tests/test_pytypes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
from pybind11_tests import pytypes as m
1111

1212

13+
def test_bool(doc):
14+
assert doc(m.get_bool) == "get_bool() -> bool"
15+
16+
1317
def test_int(doc):
1418
assert doc(m.get_int) == "get_int() -> int"
1519

@@ -22,6 +26,10 @@ def test_iterable(doc):
2226
assert doc(m.get_iterable) == "get_iterable() -> Iterable"
2327

2428

29+
def test_float(doc):
30+
assert doc(m.get_float) == "get_float() -> float"
31+
32+
2533
def test_list(capture, doc):
2634
assert m.list_no_args() == []
2735
assert m.list_ssize_t() == []

0 commit comments

Comments
 (0)