Skip to content

Commit

Permalink
regen integration test bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Nov 15, 2024
1 parent 7447a06 commit 90590c5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 145 deletions.
74 changes: 12 additions & 62 deletions src/litgen/integration_tests/_pydef_nanobind/nanobind_mylib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,30 +1855,12 @@ void py_init_module_lg_mylib(nb::module_& m)
nb::overload_cast<N::EC>(N::Foo), nb::arg("e") = N::EC::a);

pyNsN.def("foo",
[](const std::optional<const N::E> & e = std::nullopt)
{
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const N::E> & e = std::nullopt)
{

const N::E& e_or_default = [&]() -> const N::E {
if (e.has_value())
return e.value();
else
return N::E_a;
}();

N::Foo(e_or_default);
};

Foo_adapt_mutable_param_with_default_value(e);
},
nb::arg("e") = nb::none(),
"---\nPython bindings defaults:\n If e is None, then its default value will be: N.E.a");
nb::overload_cast<N::E>(N::Foo), nb::arg("e") = N::E_a);

pyNsN.def("foo",
[](const std::optional<const N::S> & s = std::nullopt, const std::optional<const N::E> & e = std::nullopt)
[](const std::optional<const N::S> & s = std::nullopt, N::E e = N::E_a)
{
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const N::S> & s = std::nullopt, const std::optional<const N::E> & e = std::nullopt)
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const N::S> & s = std::nullopt, N::E e = N::E_a)
{

const N::S& s_or_default = [&]() -> const N::S {
Expand All @@ -1888,20 +1870,13 @@ void py_init_module_lg_mylib(nb::module_& m)
return N::S();
}();

const N::E& e_or_default = [&]() -> const N::E {
if (e.has_value())
return e.value();
else
return N::E_a;
}();

N::Foo(s_or_default, e_or_default);
N::Foo(s_or_default, e);
};

Foo_adapt_mutable_param_with_default_value(s, e);
},
nb::arg("s") = nb::none(), nb::arg("e") = nb::none(),
"---\nPython bindings defaults:\n If any of the params below is None, then its default value below will be used:\n s: N.S()\n e: N.E.a");
nb::arg("s") = nb::none(), nb::arg("e") = N::E_a,
"---\nPython bindings defaults:\n If s is None, then its default value will be: N.S()");
} // </namespace N>

{ // <namespace A>
Expand Down Expand Up @@ -1956,30 +1931,12 @@ void py_init_module_lg_mylib(nb::module_& m)
nb::overload_cast<A::N::EC>(A::N::Foo), nb::arg("e") = A::N::EC::a);

pyNsA_NsN.def("foo",
[](const std::optional<const A::N::E> & e = std::nullopt)
{
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const A::N::E> & e = std::nullopt)
{

const A::N::E& e_or_default = [&]() -> const A::N::E {
if (e.has_value())
return e.value();
else
return A::N::E_a;
}();

A::N::Foo(e_or_default);
};

Foo_adapt_mutable_param_with_default_value(e);
},
nb::arg("e") = nb::none(),
"---\nPython bindings defaults:\n If e is None, then its default value will be: A.N.E.a");
nb::overload_cast<A::N::E>(A::N::Foo), nb::arg("e") = A::N::E_a);

pyNsA_NsN.def("foo",
[](const std::optional<const A::N::S> & s = std::nullopt, const std::optional<const A::N::E> & e = std::nullopt)
[](const std::optional<const A::N::S> & s = std::nullopt, A::N::E e = A::N::E_a)
{
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const A::N::S> & s = std::nullopt, const std::optional<const A::N::E> & e = std::nullopt)
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const A::N::S> & s = std::nullopt, A::N::E e = A::N::E_a)
{

const A::N::S& s_or_default = [&]() -> const A::N::S {
Expand All @@ -1989,20 +1946,13 @@ void py_init_module_lg_mylib(nb::module_& m)
return A::N::S();
}();

const A::N::E& e_or_default = [&]() -> const A::N::E {
if (e.has_value())
return e.value();
else
return A::N::E_a;
}();

A::N::Foo(s_or_default, e_or_default);
A::N::Foo(s_or_default, e);
};

Foo_adapt_mutable_param_with_default_value(s, e);
},
nb::arg("s") = nb::none(), nb::arg("e") = nb::none(),
"---\nPython bindings defaults:\n If any of the params below is None, then its default value below will be used:\n s: A.N.S()\n e: A.N.E.a");
nb::arg("s") = nb::none(), nb::arg("e") = A::N::E_a,
"---\nPython bindings defaults:\n If s is None, then its default value will be: A.N.S()");
} // </namespace N>

} // </namespace A>
Expand Down
74 changes: 12 additions & 62 deletions src/litgen/integration_tests/_pydef_pybind11/pybind_mylib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1818,30 +1818,12 @@ void py_init_module_lg_mylib(py::module& m)
py::overload_cast<N::EC>(N::Foo), py::arg("e") = N::EC::a);

pyNsN.def("foo",
[](const std::optional<const N::E> & e = std::nullopt)
{
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const N::E> & e = std::nullopt)
{

const N::E& e_or_default = [&]() -> const N::E {
if (e.has_value())
return e.value();
else
return N::E_a;
}();

N::Foo(e_or_default);
};

Foo_adapt_mutable_param_with_default_value(e);
},
py::arg("e") = py::none(),
"---\nPython bindings defaults:\n If e is None, then its default value will be: N.E.a");
py::overload_cast<N::E>(N::Foo), py::arg("e") = N::E_a);

pyNsN.def("foo",
[](const std::optional<const N::S> & s = std::nullopt, const std::optional<const N::E> & e = std::nullopt)
[](const std::optional<const N::S> & s = std::nullopt, N::E e = N::E_a)
{
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const N::S> & s = std::nullopt, const std::optional<const N::E> & e = std::nullopt)
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const N::S> & s = std::nullopt, N::E e = N::E_a)
{

const N::S& s_or_default = [&]() -> const N::S {
Expand All @@ -1851,20 +1833,13 @@ void py_init_module_lg_mylib(py::module& m)
return N::S();
}();

const N::E& e_or_default = [&]() -> const N::E {
if (e.has_value())
return e.value();
else
return N::E_a;
}();

N::Foo(s_or_default, e_or_default);
N::Foo(s_or_default, e);
};

Foo_adapt_mutable_param_with_default_value(s, e);
},
py::arg("s") = py::none(), py::arg("e") = py::none(),
"---\nPython bindings defaults:\n If any of the params below is None, then its default value below will be used:\n s: N.S()\n e: N.E.a");
py::arg("s") = py::none(), py::arg("e") = N::E_a,
"---\nPython bindings defaults:\n If s is None, then its default value will be: N.S()");
} // </namespace N>

{ // <namespace A>
Expand Down Expand Up @@ -1920,30 +1895,12 @@ void py_init_module_lg_mylib(py::module& m)
py::overload_cast<A::N::EC>(A::N::Foo), py::arg("e") = A::N::EC::a);

pyNsA_NsN.def("foo",
[](const std::optional<const A::N::E> & e = std::nullopt)
{
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const A::N::E> & e = std::nullopt)
{

const A::N::E& e_or_default = [&]() -> const A::N::E {
if (e.has_value())
return e.value();
else
return A::N::E_a;
}();

A::N::Foo(e_or_default);
};

Foo_adapt_mutable_param_with_default_value(e);
},
py::arg("e") = py::none(),
"---\nPython bindings defaults:\n If e is None, then its default value will be: A.N.E.a");
py::overload_cast<A::N::E>(A::N::Foo), py::arg("e") = A::N::E_a);

pyNsA_NsN.def("foo",
[](const std::optional<const A::N::S> & s = std::nullopt, const std::optional<const A::N::E> & e = std::nullopt)
[](const std::optional<const A::N::S> & s = std::nullopt, A::N::E e = A::N::E_a)
{
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const A::N::S> & s = std::nullopt, const std::optional<const A::N::E> & e = std::nullopt)
auto Foo_adapt_mutable_param_with_default_value = [](const std::optional<const A::N::S> & s = std::nullopt, A::N::E e = A::N::E_a)
{

const A::N::S& s_or_default = [&]() -> const A::N::S {
Expand All @@ -1953,20 +1910,13 @@ void py_init_module_lg_mylib(py::module& m)
return A::N::S();
}();

const A::N::E& e_or_default = [&]() -> const A::N::E {
if (e.has_value())
return e.value();
else
return A::N::E_a;
}();

A::N::Foo(s_or_default, e_or_default);
A::N::Foo(s_or_default, e);
};

Foo_adapt_mutable_param_with_default_value(s, e);
},
py::arg("s") = py::none(), py::arg("e") = py::none(),
"---\nPython bindings defaults:\n If any of the params below is None, then its default value below will be used:\n s: A.N.S()\n e: A.N.E.a");
py::arg("s") = py::none(), py::arg("e") = A::N::E_a,
"---\nPython bindings defaults:\n If s is None, then its default value will be: A.N.S()");
} // </namespace N>

} // </namespace A>
Expand Down
30 changes: 9 additions & 21 deletions src/litgen/integration_tests/_stubs/lg_mylib/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,8 @@ class some_namespace: # Proxy class that introduces typings for the *submodule*
inner_enum: InnerEnum = InnerEnum.three
def __init__(
self,
inner_struct: Optional[SomeNamespace.ParentStruct.InnerStruct] = None,
inner_enum: SomeNamespace.ParentStruct.InnerEnum = SomeNamespace.ParentStruct.InnerEnum.three,
inner_struct: Optional[ParentStruct.InnerStruct] = None,
inner_enum: ParentStruct.InnerEnum = ParentStruct.InnerEnum.three,
) -> None:
"""Auto-generated default constructor with named params
---
Expand Down Expand Up @@ -1212,20 +1212,14 @@ class n: # Proxy class that introduces typings for the *submodule* n
pass
@staticmethod
@overload
def foo(e: Optional[E] = None) -> None:
"""---
Python bindings defaults:
If e is None, then its default value will be: N.E.a
"""
def foo(e: E = E.a) -> None:
pass
@staticmethod
@overload
def foo(s: Optional[S] = None, e: Optional[E] = None) -> None:
def foo(s: Optional[S] = None, e: E = E.a) -> None:
"""---
Python bindings defaults:
If any of the params below is None, then its default value below will be used:
s: N.S()
e: N.E.a
If s is None, then its default value will be: N.S()
"""
pass

Expand All @@ -1251,7 +1245,7 @@ class a: # Proxy class that introduces typings for the *submodule* a
foo: Foo = Foo.foo1
s: str = "Allo" # (const)
def __init__(
self, b: bool = True, a: int = int(), c: int = 3, foo: A.Foo = A.Foo.foo1
self, b: bool = True, a: int = int(), c: int = 3, foo: Foo = Foo.foo1
) -> None:
"""Auto-generated default constructor with named params"""
pass
Expand All @@ -1276,20 +1270,14 @@ class a: # Proxy class that introduces typings for the *submodule* a
pass
@staticmethod
@overload
def foo(e: Optional[E] = None) -> None:
"""---
Python bindings defaults:
If e is None, then its default value will be: A.N.E.a
"""
def foo(e: E = E.a) -> None:
pass
@staticmethod
@overload
def foo(s: Optional[S] = None, e: Optional[E] = None) -> None:
def foo(s: Optional[S] = None, e: E = E.a) -> None:
"""---
Python bindings defaults:
If any of the params below is None, then its default value below will be used:
s: A.N.S()
e: A.N.E.a
If s is None, then its default value will be: A.N.S()
"""
pass
# </submodule n>
Expand Down

0 comments on commit 90590c5

Please sign in to comment.