Skip to content

Commit

Permalink
documentation/python: expand pybind default enum argument tests.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
mosra committed Jan 3, 2022
1 parent 7301a85 commit cca2d44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum class Enum {
First, Second
};

void typeEnum(Enum) {}
void typeEnumAndDefault(Enum) {}

struct Foo {
Enum property;
Expand All @@ -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) {
Expand All @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ <h2><a href="#enums">Enums</a></h2>
<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>
Expand Down

0 comments on commit cca2d44

Please sign in to comment.