Skip to content
Open
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
8 changes: 7 additions & 1 deletion pybind11_stubgen/parser/mixins/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,15 @@ def parse_annotation_str(
) -> ResolvedType | InvalidExpression | Value:
result = super().parse_annotation_str(annotation_str)
if isinstance(result, ResolvedType):
result.name = self._strip_current_module(result.name)
self._strip_current_module_recursive(result)
return result

def _strip_current_module_recursive(self, result: ResolvedType):
result.name = self._strip_current_module(result.name)
for parameter in result.parameters or ():
if isinstance(parameter, ResolvedType):
self._strip_current_module_recursive(parameter)

def _strip_current_module(self, name: QualifiedName) -> QualifiedName:
if name[: len(self.__current_module)] == self.__current_module:
return QualifiedName(name[len(self.__current_module) :])
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,4 +100,5 @@ 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; });
}
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",
"pos_kw_only_mix",
"pos_kw_only_variadic_mix",
Expand Down Expand Up @@ -51,6 +52,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: ...
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: ...
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: ...
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: ...
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",
"pos_kw_only_mix",
"pos_kw_only_variadic_mix",
Expand Down Expand Up @@ -49,6 +50,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: ...
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: ...