From 483871168c315bc31107df1d0bcd31fc7ba37dcc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 28 Jun 2023 15:42:36 +0200 Subject: [PATCH] documentation/python: test external doc overload matching with * and /. With the previous commit this now "just works", as the placeholders are dropped from the final signature. The test thus works mainly for documenting this feature. --- .../pybind_external_overload_docs/docs.rst | 4 + ...pybind_external_overload_docs.Class26.html | 77 +++++++++++++++++++ .../pybind_external_overload_docs.cpp | 22 ++++++ .../pybind_external_overload_docs.html | 2 + documentation/test_python/test_pybind.py | 5 ++ 5 files changed, 110 insertions(+) create mode 100644 documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.Class26.html diff --git a/documentation/test_python/pybind_external_overload_docs/docs.rst b/documentation/test_python/pybind_external_overload_docs/docs.rst index 242c1c22..2499e017 100644 --- a/documentation/test_python/pybind_external_overload_docs/docs.rst +++ b/documentation/test_python/pybind_external_overload_docs/docs.rst @@ -30,6 +30,10 @@ And the fallback matching works there, too. +.. py:function:: pybind_external_overload_docs.Class26.foo(self, a: int, b: float, keyword: str) + + The ``/`` and ``*`` are excluded from matching. + .. py:function:: pybind_external_overload_docs.foo(first: int) :param second: But the second argument doesn't exist?! diff --git a/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.Class26.html b/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.Class26.html new file mode 100644 index 00000000..2a742e79 --- /dev/null +++ b/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.Class26.html @@ -0,0 +1,77 @@ + + + + + pybind_external_overload_docs.Class26 | My Python Project + + + + + +
+
+
+
+
+

+ pybind_external_overload_docs.Class26 class +

+

Pybind 2.6 features

+ +
+

Methods

+
+
+ def foo(self, + a: int, /, + b: float, *, + keyword: str) -> None +
+
Positional and keyword-only arguments
+
+
+
+

Data

+
+
+ is_pybind26 = True +
+
+
+
+
+

Method documentation

+
+

+ def pybind_external_overload_docs.Class26.foo(self, + a: int, /, + b: float, *, + keyword: str) -> None +

+

Positional and keyword-only arguments

+

The / and * are excluded from matching.

+
+
+
+
+
+
+ + diff --git a/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.cpp b/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.cpp index e5e8260a..59415962 100644 --- a/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.cpp +++ b/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.cpp @@ -15,6 +15,11 @@ struct Class { void foo2(std::string) {} }; +struct Class26 { + void foo1(int) {} + void foo2(int, float, const std::string&) {} +}; + PYBIND11_MODULE(pybind_external_overload_docs, m) { m.doc() = "pybind11 external overload docs"; @@ -28,4 +33,21 @@ PYBIND11_MODULE(pybind_external_overload_docs, m) { py::class_(m, "Class", "My fun class!") .def("foo", &Class::foo1, "First overload", py::arg("index")) .def("foo", &Class::foo2, "Second overload", py::arg("name")); + + py::class_ pybind26{m, "Class26", "Pybind 2.6 features"}; + + /* Checker so the Python side can detect if testing pybind 2.6 features is + feasible */ + pybind26.attr("is_pybind26") = + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + true + #else + false + #endif + ; + + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + pybind26 + .def("foo", &Class26::foo2, "Positional and keyword-only arguments", py::arg("a"), py::pos_only{}, py::arg("b"), py::kw_only{}, py::arg("keyword")); + #endif } diff --git a/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.html b/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.html index 2766849c..f0f54110 100644 --- a/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.html +++ b/documentation/test_python/pybind_external_overload_docs/pybind_external_overload_docs.html @@ -40,6 +40,8 @@
class Class
My fun class!
+
class Class26
+
Pybind 2.6 features
diff --git a/documentation/test_python/test_pybind.py b/documentation/test_python/test_pybind.py index 2905aa61..3865d97c 100644 --- a/documentation/test_python/test_pybind.py +++ b/documentation/test_python/test_pybind.py @@ -419,3 +419,8 @@ class ExternalOverloadDocs(BaseInspectTestCase): }) self.assertEqual(*self.actual_expected_contents('pybind_external_overload_docs.html')) self.assertEqual(*self.actual_expected_contents('pybind_external_overload_docs.Class.html')) + + sys.path.append(self.path) + import pybind_external_overload_docs + if pybind_external_overload_docs.Class26.is_pybind26: + self.assertEqual(*self.actual_expected_contents('pybind_external_overload_docs.Class26.html')) -- 2.30.2