From cca2d44e700a9cece6cf0b91fd8aeed293c1b63c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 3 Jan 2022 00:06:27 +0100 Subject: [PATCH] documentation/python: expand pybind default enum argument tests. To verify also a case with an enum nested in a pair (which won't get linked to because we're not *that* advanced yet). --- .../pybind_type_links/pybind_type_links.cpp | 9 ++++++--- .../pybind_type_links/pybind_type_links.html | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/documentation/test_python/pybind_type_links/pybind_type_links.cpp b/documentation/test_python/pybind_type_links/pybind_type_links.cpp index eb54661a..eed8fb5a 100644 --- a/documentation/test_python/pybind_type_links/pybind_type_links.cpp +++ b/documentation/test_python/pybind_type_links/pybind_type_links.cpp @@ -9,7 +9,7 @@ enum class Enum { First, Second }; -void typeEnum(Enum) {} +void typeEnumAndDefault(Enum) {} struct Foo { Enum property; @@ -19,6 +19,8 @@ Foo typeReturn() { return {}; } void typeNested(const std::pair>&) {} +void typeNestedEnumAndDefault(std::pair) {} + } PYBIND11_MODULE(pybind_type_links, m) { @@ -34,9 +36,10 @@ PYBIND11_MODULE(pybind_type_links, m) { .def_readwrite("property", &Foo::property, "A property"); m - .def("type_enum", &typeEnum, "A function taking an enum", py::arg("value") = Enum::Second) + .def("type_enum_and_default", &typeEnumAndDefault, "A function taking an enum with a default", py::arg("value") = Enum::Second) .def("type_return", &typeReturn, "A function returning a type") - .def("type_nested", &typeNested, "A function with nested type annotation"); + .def("type_nested", &typeNested, "A function with nested type annotation") + .def("type_nested_enum_and_default", &typeNestedEnumAndDefault, "A function taking a nested enum with a default. This won't have a link.", py::arg("value") = std::pair{3, Enum::First}); /* Test also attributes (annotated from within Python) */ m.attr("TYPE_DATA") = Foo{Enum::First}; diff --git a/documentation/test_python/pybind_type_links/pybind_type_links.html b/documentation/test_python/pybind_type_links/pybind_type_links.html index 9c3c1965..b1239b43 100644 --- a/documentation/test_python/pybind_type_links/pybind_type_links.html +++ b/documentation/test_python/pybind_type_links/pybind_type_links.html @@ -57,14 +57,18 @@

Functions

-
- def type_enum(value: Enum = Enum.SECOND) -> None +
+ def type_enum_and_default(value: Enum = Enum.SECOND) -> None
-
A function taking an enum
+
A function taking an enum with a default
def type_nested(arg0: typing.Tuple[Foo, typing.List[Enum]], /) -> None
A function with nested type annotation
+
+ def type_nested_enum_and_default(value: typing.Tuple[int, Enum] = (3, Enum.FIRST)) -> None +
+
A function taking a nested enum with a default. This won't have a link.
def type_return() -> Foo
-- 2.30.2