Skip to content

Commit 8941fde

Browse files
committed
fix: Handle typing and non-typing generics
1 parent 025a6f3 commit 8941fde

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pybind11_stubgen/parser/mixins/parse.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import inspect
66
import re
77
import types
8+
import typing
89
from typing import Any
910

1011
from pybind11_stubgen.parser.errors import (
@@ -252,16 +253,16 @@ def handle_function(self, path: QualifiedName, func: Any) -> list[Function]:
252253
func_args[arg_name].annotation = self.parse_annotation_str(
253254
annotation
254255
)
255-
elif not isinstance(annotation, type):
256-
func_args[arg_name].annotation = self.handle_value(annotation)
257256
elif self._is_generic_alias(annotation):
258257
func_args[arg_name].annotation = self.parse_annotation_str(
259258
str(annotation)
260259
)
261-
else:
260+
elif isinstance(annotation, type):
262261
func_args[arg_name].annotation = ResolvedType(
263262
name=self.handle_type(annotation),
264263
)
264+
else:
265+
func_args[arg_name].annotation = self.handle_value(annotation)
265266
if "return" in func_args:
266267
returns = func_args["return"].annotation
267268
else:
@@ -293,7 +294,10 @@ def _is_generic_alias(self, annotation: type) -> bool:
293294
generic_alias_t: type | None = getattr(types, "GenericAlias", None)
294295
if generic_alias_t is None:
295296
return False
296-
return isinstance(annotation, generic_alias_t)
297+
typing_generic_alias_t = type(typing.List[int])
298+
return isinstance(annotation, generic_alias_t) or isinstance(
299+
annotation, typing_generic_alias_t
300+
)
297301

298302
def handle_import(self, path: QualifiedName, origin: Any) -> Import | None:
299303
full_name = self._get_full_name(path, origin)

0 commit comments

Comments
 (0)