Skip to content

Commit

Permalink
Render py::bool_ and py::float_ without _ in docstrings (#3622)
Browse files Browse the repository at this point in the history
* Render `py::bool_` as `bool` in docstrings

* Render `py::float_` as `float` in docstrings
  • Loading branch information
sizmailov authored Jan 16, 2022
1 parent 7e7c558 commit 5194855
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,12 @@ template <typename base, typename deleter> struct is_holder_type<base, std::uniq
std::true_type {};

template <typename T> struct handle_type_name { static constexpr auto name = const_name<T>(); };
template <> struct handle_type_name<bool_> { static constexpr auto name = const_name("bool"); };
template <> struct handle_type_name<bytes> { static constexpr auto name = const_name(PYBIND11_BYTES_NAME); };
template <> struct handle_type_name<int_> { static constexpr auto name = const_name("int"); };
template <> struct handle_type_name<iterable> { static constexpr auto name = const_name("Iterable"); };
template <> struct handle_type_name<iterator> { static constexpr auto name = const_name("Iterator"); };
template <> struct handle_type_name<float_> { static constexpr auto name = const_name("float"); };
template <> struct handle_type_name<none> { static constexpr auto name = const_name("None"); };
template <> struct handle_type_name<args> { static constexpr auto name = const_name("*args"); };
template <> struct handle_type_name<kwargs> { static constexpr auto name = const_name("**kwargs"); };
Expand Down
4 changes: 4 additions & 0 deletions tests/test_pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}; });
Expand Down
8 changes: 8 additions & 0 deletions tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
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"

Expand All @@ -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() == []
Expand Down

0 comments on commit 5194855

Please sign in to comment.