From: Vladimír Vondruš Date: Tue, 7 May 2019 22:26:21 +0000 (+0200) Subject: documentation/python: support more than 9 function overloads. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=759bf1ab74cb1437e77816afed1d0c2edd6af61a;p=blog.git documentation/python: support more than 9 function overloads. I thought this time would never come. But here we are, math.dot() needs this. --- diff --git a/documentation/python.py b/documentation/python.py index c2eb7a6d..97714ecd 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -293,14 +293,11 @@ def parse_pybind_docstring(state: State, name: str, doc: str) -> List[Tuple[str, next = doc.find('{}. {}('.format(id, name)) # Parse the signature and docs from known slice - overloads += [parse_pybind_signature(state, doc[3:next])] + overloads += [parse_pybind_signature(state, doc[len(str(id - 1)) + 2:next])] assert overloads[-1][0] == name if next == -1: break - # Continue to the next signature. Sorry, didn't bother to check how - # docstrings for more than 9 overloads look yet, that's why the - # assert - assert id < 10 + # Continue to the next signature doc = doc[next:] return overloads diff --git a/documentation/test_python/pybind_signatures/pybind_signatures.cpp b/documentation/test_python/pybind_signatures/pybind_signatures.cpp index 40d055fb..79cd63e4 100644 --- a/documentation/test_python/pybind_signatures/pybind_signatures.cpp +++ b/documentation/test_python/pybind_signatures/pybind_signatures.cpp @@ -35,6 +35,8 @@ struct MyClass { void duck(py::args, py::kwargs) {} +template void tenOverloads(T, U) {} + PYBIND11_MODULE(pybind_signatures, m) { m.doc() = "pybind11 function signature extraction"; @@ -46,7 +48,18 @@ PYBIND11_MODULE(pybind_signatures, m) { .def("crazy_signature", &crazySignature, "Function that failed to get parsed") .def("overloaded", static_cast(&overloaded), "Overloaded for ints") .def("overloaded", static_cast(&overloaded), "Overloaded for floats") - .def("duck", &duck, "A function taking args/kwargs directly"); + .def("duck", &duck, "A function taking args/kwargs directly") + + .def("tenOverloads", &tenOverloads, "Ten overloads of a function") + .def("tenOverloads", &tenOverloads, "Ten overloads of a function") + .def("tenOverloads", &tenOverloads, "Ten overloads of a function") + .def("tenOverloads", &tenOverloads, "Ten overloads of a function") + .def("tenOverloads", &tenOverloads, "Ten overloads of a function") + .def("tenOverloads", &tenOverloads, "Ten overloads of a function") + .def("tenOverloads", &tenOverloads, "Ten overloads of a function") + .def("tenOverloads", &tenOverloads, "Ten overloads of a function") + .def("tenOverloads", &tenOverloads, "Ten overloads of a function") + .def("tenOverloads", &tenOverloads, "Ten overloads of a function"); py::class_(m, "MyClass", "My fun class!") .def_static("static_function", &MyClass::staticFunction, "Static method with positional-only args") diff --git a/documentation/test_python/pybind_signatures/pybind_signatures.html b/documentation/test_python/pybind_signatures/pybind_signatures.html index b314bfcf..ddaa5674 100644 --- a/documentation/test_python/pybind_signatures/pybind_signatures.html +++ b/documentation/test_python/pybind_signatures/pybind_signatures.html @@ -75,6 +75,56 @@ def taking_a_list_returning_a_tuple(arg0: List[float], /) -> Tuple[int, int, int]
Takes a list, returns a tuple
+
+ def tenOverloads(arg0: float, + arg1: float, /) +
+
Ten overloads of a function
+
+ def tenOverloads(arg0: int, + arg1: float, /) +
+
Ten overloads of a function
+
+ def tenOverloads(arg0: bool, + arg1: float, /) +
+
Ten overloads of a function
+
+ def tenOverloads(arg0: float, + arg1: int, /) +
+
Ten overloads of a function
+
+ def tenOverloads(arg0: int, + arg1: int, /) +
+
Ten overloads of a function
+
+ def tenOverloads(arg0: bool, + arg1: int, /) +
+
Ten overloads of a function
+
+ def tenOverloads(arg0: float, + arg1: bool, /) +
+
Ten overloads of a function
+
+ def tenOverloads(arg0: int, + arg1: bool, /) +
+
Ten overloads of a function
+
+ def tenOverloads(arg0: bool, + arg1: bool, /) +
+
Ten overloads of a function
+
+ def tenOverloads(arg0: str, + arg1: str, /) +
+
Ten overloads of a function
def void_function(arg0: int, /)