Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pybind11_stubgen/parser/mixins/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def parse_annotation_str(
assert isinstance(union_t, ResolvedType)
return ResolvedType(
name=union_t.name,
parameters=[self.parse_type_str(variant) for variant in variants],
parameters=[self.parse_annotation_str(variant) for variant in variants],
)

def parse_type_str(
Expand Down
4 changes: 4 additions & 0 deletions tests/py-demo/bindings/src/modules/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <pybind11/stl.h>
#include <pybind11/functional.h>

#include <variant>
#include <list>

#include <demo/sublibA/add.h>

namespace {
Expand Down Expand Up @@ -97,6 +100,7 @@ void bind_functions_module(py::module &&m) {
pyFoo.def(py::init<int>());
m.def("default_custom_arg", [](Foo &foo) {}, py::arg_v("foo", Foo(5), "Foo(5)"));
m.def("pass_callback", [](std::function<Foo(Foo &)> &callback) { return Foo(13); });
m.def("nested_types", [](std::variant<std::list<Foo>, Foo> arg){ return arg; });

#if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 12)
py::options options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ __all__: list[str] = [
"func_w_named_pos_args",
"generic",
"mul",
"nested_types",
"pass_callback",
"passthrough1",
"passthrough2",
Expand Down Expand Up @@ -54,6 +55,7 @@ def mul(p: float, q: float) -> float:
Multiply p and q (double)
"""

def nested_types(arg0: list[Foo] | Foo) -> list[Foo] | Foo: ...
def pass_callback(arg0: typing.Callable[[Foo], Foo]) -> Foo: ...
def passthrough1[T](obj: T) -> T: ...
@typing.overload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ __all__: list[str] = [
"func_w_named_pos_args",
"generic",
"mul",
"nested_types",
"pass_callback",
"passthrough1",
"passthrough2",
Expand Down Expand Up @@ -56,6 +57,7 @@ def mul(p: float, q: float) -> float:
Multiply p and q (double)
"""

def nested_types(arg0: list[Foo] | Foo) -> list[Foo] | Foo: ...
def pass_callback(arg0: typing.Callable[[Foo], Foo]) -> Foo: ...
def passthrough1[T](obj: T) -> T: ...
@typing.overload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ __all__: list[str] = [
"func_w_named_pos_args",
"generic",
"mul",
"nested_types",
"pass_callback",
"passthrough1",
"passthrough2",
Expand Down Expand Up @@ -56,6 +57,7 @@ def mul(p: float, q: float) -> float:
Multiply p and q (double)
"""

def nested_types(arg0: list[Foo] | Foo) -> list[Foo] | Foo: ...
def pass_callback(arg0: typing.Callable[[Foo], Foo]) -> Foo: ...
def passthrough1[T](obj: T) -> T: ...
@typing.overload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ __all__: list[str] = [
"func_w_named_pos_args",
"generic",
"mul",
"nested_types",
"pass_callback",
"passthrough1",
"passthrough2",
Expand Down Expand Up @@ -56,6 +57,7 @@ def mul(p: float, q: float) -> float:
Multiply p and q (double)
"""

def nested_types(arg0: list[Foo] | Foo) -> list[Foo] | Foo: ...
def pass_callback(arg0: typing.Callable[[Foo], Foo]) -> Foo: ...
def passthrough1[T](obj: T) -> T: ...
@typing.overload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ __all__: list[str] = [
"func_w_named_pos_args",
"generic",
"mul",
"nested_types",
"pass_callback",
"passthrough1",
"passthrough2",
Expand Down Expand Up @@ -52,6 +53,7 @@ def mul(p: float, q: float) -> float:
Multiply p and q (double)
"""

def nested_types(arg0: list[Foo] | Foo) -> list[Foo] | Foo: ...
def pass_callback(arg0: typing.Callable[[Foo], Foo]) -> Foo: ...
def passthrough1[T](obj: T) -> T: ...
@typing.overload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ __all__: list[str] = [
"func_w_named_pos_args",
"generic",
"mul",
"nested_types",
"pass_callback",
"passthrough1",
"passthrough2",
Expand Down Expand Up @@ -63,6 +64,7 @@ def mul(p: typing.SupportsFloat, q: typing.SupportsFloat) -> float:
Multiply p and q (double)
"""

def nested_types(arg0: collections.abc.Sequence[Foo] | Foo) -> list[Foo] | Foo: ...
def pass_callback(arg0: collections.abc.Callable[[Foo], Foo]) -> Foo: ...
def passthrough1[T](obj: T) -> T: ...
@typing.overload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ __all__: list[str] = [
"func_w_named_pos_args",
"generic",
"mul",
"nested_types",
"pass_callback",
"passthrough1",
"passthrough2",
Expand Down Expand Up @@ -63,6 +64,7 @@ def mul(p: typing.SupportsFloat, q: typing.SupportsFloat) -> float:
Multiply p and q (double)
"""

def nested_types(arg0: collections.abc.Sequence[Foo] | Foo) -> list[Foo] | Foo: ...
def pass_callback(arg0: collections.abc.Callable[[Foo], Foo]) -> Foo: ...
def passthrough1[T](obj: T) -> T: ...
@typing.overload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ __all__: list[str] = [
"func_w_named_pos_args",
"generic",
"mul",
"nested_types",
"pass_callback",
"pos_kw_only_mix",
"pos_kw_only_variadic_mix",
Expand Down Expand Up @@ -53,6 +54,7 @@ def mul(p: float, q: float) -> float:
Multiply p and q (double)
"""

def nested_types(arg0: list[Foo] | Foo) -> list[Foo] | Foo: ...
def pass_callback(arg0: typing.Callable[[Foo], Foo]) -> Foo: ...
def pos_kw_only_mix(i: int, /, j: int, *, k: int) -> tuple: ...
def pos_kw_only_variadic_mix(i: int, /, j: int, *args, k: int, **kwargs) -> tuple: ...