chiark / gitweb /
documentation/python: expand pybind default enum argument tests.
authorVladimír Vondruš <mosra@centrum.cz>
Sun, 2 Jan 2022 23:06:27 +0000 (00:06 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 3 Jan 2022 01:36:44 +0000 (02:36 +0100)
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).

documentation/test_python/pybind_type_links/pybind_type_links.cpp
documentation/test_python/pybind_type_links/pybind_type_links.html

index eb54661a11064c16c41aadc4dc56f886eb02b29f..eed8fb5a3ace229b947b3b97b06e71f7ad4b513e 100644 (file)
@@ -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<Foo, std::vector<Enum>>&) {}
 
+void typeNestedEnumAndDefault(std::pair<int, Enum>) {}
+
 }
 
 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<int, Enum>{3, Enum::First});
 
     /* Test also attributes (annotated from within Python) */
     m.attr("TYPE_DATA") = Foo{Enum::First};
index 9c3c196570914e467ee4e4fe07d4c045edafc6f1..b1239b438ea9ad1d8d153dd02afac9189293262f 100644 (file)
         <section id="functions">
           <h2><a href="#functions">Functions</a></h2>
           <dl class="m-doc">
-            <dt id="type_enum">
-              <span class="m-doc-wrap-bumper">def <a href="#type_enum" class="m-doc-self">type_enum</a>(</span><span class="m-doc-wrap">value: <a href="pybind_type_links.html#Enum" class="m-doc">Enum</a> = <a href="pybind_type_links.html#Enum-SECOND" class="m-doc">Enum.SECOND</a>) -&gt; <a href="https://docs.python.org/3/library/constants.html#None" class="m-doc-external">None</a></span>
+            <dt id="type_enum_and_default">
+              <span class="m-doc-wrap-bumper">def <a href="#type_enum_and_default" class="m-doc-self">type_enum_and_default</a>(</span><span class="m-doc-wrap">value: <a href="pybind_type_links.html#Enum" class="m-doc">Enum</a> = <a href="pybind_type_links.html#Enum-SECOND" class="m-doc">Enum.SECOND</a>) -&gt; <a href="https://docs.python.org/3/library/constants.html#None" class="m-doc-external">None</a></span>
             </dt>
-            <dd>A function taking an enum</dd>
+            <dd>A function taking an enum with a default</dd>
             <dt id="type_nested">
               <span class="m-doc-wrap-bumper">def <a href="#type_nested" class="m-doc-self">type_nested</a>(</span><span class="m-doc-wrap">arg0: <a href="https://docs.python.org/3/library/typing.html#typing.Tuple" class="m-doc-external">typing.Tuple</a>[<a href="pybind_type_links.Foo.html" class="m-doc">Foo</a>, <a href="https://docs.python.org/3/library/typing.html#typing.List" class="m-doc-external">typing.List</a>[<a href="pybind_type_links.html#Enum" class="m-doc">Enum</a>]]<span class="m-text m-dim">, /</span>) -&gt; <a href="https://docs.python.org/3/library/constants.html#None" class="m-doc-external">None</a></span>
             </dt>
             <dd>A function with nested type annotation</dd>
+            <dt id="type_nested_enum_and_default">
+              <span class="m-doc-wrap-bumper">def <a href="#type_nested_enum_and_default" class="m-doc-self">type_nested_enum_and_default</a>(</span><span class="m-doc-wrap">value: <a href="https://docs.python.org/3/library/typing.html#typing.Tuple" class="m-doc-external">typing.Tuple</a>[<a href="https://docs.python.org/3/library/functions.html#int" class="m-doc-external">int</a>, <a href="pybind_type_links.html#Enum" class="m-doc">Enum</a>] = (3, Enum.FIRST)) -&gt; <a href="https://docs.python.org/3/library/constants.html#None" class="m-doc-external">None</a></span>
+            </dt>
+            <dd>A function taking a nested enum with a default. This won&#x27;t have a link.</dd>
             <dt id="type_return">
               <span class="m-doc-wrap-bumper">def <a href="#type_return" class="m-doc-self">type_return</a>(</span><span class="m-doc-wrap">) -&gt; <a href="pybind_type_links.Foo.html" class="m-doc">Foo</a></span>
             </dt>