Skip to content

Commit d4e6f86

Browse files
committed
Render py::float_ as float in docstrings
1 parent b1f4ab2 commit d4e6f86

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

include/pybind11/cast.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ template <> struct handle_type_name<bytes> { static constexpr auto name = const_
770770
template <> struct handle_type_name<int_> { static constexpr auto name = const_name("int"); };
771771
template <> struct handle_type_name<iterable> { static constexpr auto name = const_name("Iterable"); };
772772
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"); };
773774
template <> struct handle_type_name<none> { static constexpr auto name = const_name("None"); };
774775
template <> struct handle_type_name<args> { static constexpr auto name = const_name("*args"); };
775776
template <> struct handle_type_name<kwargs> { static constexpr auto name = const_name("**kwargs"); };

tests/test_pytypes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ TEST_SUBMODULE(pytypes, m) {
2121
m.def("get_iterator", []{return py::iterator();});
2222
// test_iterable
2323
m.def("get_iterable", []{return py::iterable();});
24+
// test_float
25+
m.def("get_float", []{return py::float_(0.0f);});
2426
// test_list
2527
m.def("list_no_args", []() { return py::list{}; });
2628
m.def("list_ssize_t", []() { return py::list{(py::ssize_t) 0}; });

tests/test_pytypes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def test_iterable(doc):
2626
assert doc(m.get_iterable) == "get_iterable() -> Iterable"
2727

2828

29+
def test_float(doc):
30+
assert doc(m.get_iterable) == "get_float() -> float"
31+
32+
2933
def test_list(capture, doc):
3034
assert m.list_no_args() == []
3135
assert m.list_ssize_t() == []

0 commit comments

Comments
 (0)