Skip to content

Commit c3fcfa0

Browse files
ax3lgentlegiantJGCsarlinpeskarndev
authored
Fix nested qualname simple (#280)
Fixes #266 Fixes #272 Takes the tests from #272 and the simple fix from the large PR in #263. Credits to @gentlegiantJGC and @sarlinpe 🙏 --------- Co-authored-by: gentlegiantJGC <gentlegiantJGC@users.noreply.github.com> Co-authored-by: sarlinpe <paul.edouard.sarlin@gmail.com> Co-authored-by: Skarn <skarnproject@gmail.com>
1 parent f34be37 commit c3fcfa0

8 files changed

Lines changed: 17 additions & 1 deletion

File tree

  • pybind11_stubgen/parser/mixins
  • tests
    • py-demo/bindings/src/modules
    • stubs
      • python-3.12
        • pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings
        • pybind11-v2.12/numpy-array-wrap-with-annotated/demo/_bindings
        • pybind11-v2.13
        • pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings
      • python-3.8/pybind11-v2.13/numpy-array-wrap-with-annotated/demo/_bindings

pybind11_stubgen/parser/mixins/parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def parse_annotation_str(
583583
assert isinstance(union_t, ResolvedType)
584584
return ResolvedType(
585585
name=union_t.name,
586-
parameters=[self.parse_type_str(variant) for variant in variants],
586+
parameters=[self.parse_annotation_str(variant) for variant in variants],
587587
)
588588

589589
def parse_type_str(

tests/py-demo/bindings/src/modules/functions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <pybind11/stl.h>
1010
#include <pybind11/functional.h>
1111

12+
#include <variant>
13+
#include <list>
14+
1215
#include <demo/sublibA/add.h>
1316

1417
namespace {
@@ -97,4 +100,5 @@ void bind_functions_module(py::module &&m) {
97100
pyFoo.def(py::init<int>());
98101
m.def("default_custom_arg", [](Foo &foo) {}, py::arg_v("foo", Foo(5), "Foo(5)"));
99102
m.def("pass_callback", [](std::function<Foo(Foo &)> &callback) { return Foo(13); });
103+
m.def("nested_types", [](std::variant<std::list<Foo>, Foo> arg){ return arg; });
100104
}

tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/functions.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ __all__: list[str] = [
1818
"func_w_named_pos_args",
1919
"generic",
2020
"mul",
21+
"nested_types",
2122
"pass_callback",
2223
"pos_kw_only_mix",
2324
"pos_kw_only_variadic_mix",
@@ -51,6 +52,7 @@ def mul(p: float, q: float) -> float:
5152
Multiply p and q (double)
5253
"""
5354

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

tests/stubs/python-3.12/pybind11-v2.12/numpy-array-wrap-with-annotated/demo/_bindings/functions.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ __all__: list[str] = [
1919
"func_w_named_pos_args",
2020
"generic",
2121
"mul",
22+
"nested_types",
2223
"pass_callback",
2324
"pos_kw_only_mix",
2425
"pos_kw_only_variadic_mix",
@@ -53,6 +54,7 @@ def mul(p: float, q: float) -> float:
5354
Multiply p and q (double)
5455
"""
5556

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

tests/stubs/python-3.12/pybind11-v2.13/numpy-array-use-type-var/demo/_bindings/functions.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ __all__: list[str] = [
1919
"func_w_named_pos_args",
2020
"generic",
2121
"mul",
22+
"nested_types",
2223
"pass_callback",
2324
"pos_kw_only_mix",
2425
"pos_kw_only_variadic_mix",
@@ -53,6 +54,7 @@ def mul(p: float, q: float) -> float:
5354
Multiply p and q (double)
5455
"""
5556

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

tests/stubs/python-3.12/pybind11-v2.13/numpy-array-wrap-with-annotated/demo/_bindings/functions.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ __all__: list[str] = [
1919
"func_w_named_pos_args",
2020
"generic",
2121
"mul",
22+
"nested_types",
2223
"pass_callback",
2324
"pos_kw_only_mix",
2425
"pos_kw_only_variadic_mix",
@@ -53,6 +54,7 @@ def mul(p: float, q: float) -> float:
5354
Multiply p and q (double)
5455
"""
5556

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

tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/functions.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ __all__: list[str] = [
1717
"func_w_named_pos_args",
1818
"generic",
1919
"mul",
20+
"nested_types",
2021
"pass_callback",
2122
"pos_kw_only_mix",
2223
"pos_kw_only_variadic_mix",
@@ -49,6 +50,7 @@ def mul(p: float, q: float) -> float:
4950
Multiply p and q (double)
5051
"""
5152

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

tests/stubs/python-3.8/pybind11-v2.13/numpy-array-wrap-with-annotated/demo/_bindings/functions.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ __all__: list[str] = [
1919
"func_w_named_pos_args",
2020
"generic",
2121
"mul",
22+
"nested_types",
2223
"pass_callback",
2324
"pos_kw_only_mix",
2425
"pos_kw_only_variadic_mix",
@@ -53,6 +54,7 @@ def mul(p: float, q: float) -> float:
5354
Multiply p and q (double)
5455
"""
5556

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

0 commit comments

Comments
 (0)