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
60 changes: 20 additions & 40 deletions pybind11_stubgen/parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,93 +26,73 @@

class IParser(abc.ABC):
@abc.abstractmethod
def handle_alias(self, path: QualifiedName, origin: Any) -> Alias | None:
...
def handle_alias(self, path: QualifiedName, origin: Any) -> Alias | None: ...

@abc.abstractmethod
def handle_attribute(self, path: QualifiedName, attr: Any) -> Attribute | None:
...
def handle_attribute(self, path: QualifiedName, attr: Any) -> Attribute | None: ...

@abc.abstractmethod
def handle_bases(
self, path: QualifiedName, bases: tuple[type, ...]
) -> list[QualifiedName]:
...
) -> list[QualifiedName]: ...

@abc.abstractmethod
def handle_class(self, path: QualifiedName, class_: type) -> Class | None:
...
def handle_class(self, path: QualifiedName, class_: type) -> Class | None: ...

@abc.abstractmethod
def handle_class_member(
self, path: QualifiedName, class_: type, obj: Any
) -> Docstring | Alias | Class | list[Method] | Field | Property | None:
...
) -> Docstring | Alias | Class | list[Method] | Field | Property | None: ...

@abc.abstractmethod
def handle_docstring(self, path: QualifiedName, doc: Any) -> Docstring | None:
...
def handle_docstring(self, path: QualifiedName, doc: Any) -> Docstring | None: ...

@abc.abstractmethod
def handle_field(self, path: QualifiedName, field: Any) -> Field | None:
...
def handle_field(self, path: QualifiedName, field: Any) -> Field | None: ...

@abc.abstractmethod
def handle_function(self, path: QualifiedName, func: Any) -> list[Function]:
...
def handle_function(self, path: QualifiedName, func: Any) -> list[Function]: ...

@abc.abstractmethod
def handle_import(self, path: QualifiedName, origin: Any) -> Import | None:
...
def handle_import(self, path: QualifiedName, origin: Any) -> Import | None: ...

@abc.abstractmethod
def handle_method(self, path: QualifiedName, method: Any) -> list[Method]:
...
def handle_method(self, path: QualifiedName, method: Any) -> list[Method]: ...

@abc.abstractmethod
def handle_module(
self, path: QualifiedName, module: types.ModuleType
) -> Module | None:
...
) -> Module | None: ...

@abc.abstractmethod
def handle_module_member(
self, path: QualifiedName, module: types.ModuleType, obj: Any
) -> (
Docstring | Import | Alias | Class | list[Function] | Attribute | Module | None
):
...
): ...

@abc.abstractmethod
def handle_property(self, path: QualifiedName, prop: Any) -> Property | None:
...
def handle_property(self, path: QualifiedName, prop: Any) -> Property | None: ...

@abc.abstractmethod
def handle_type(self, type_: type) -> QualifiedName:
...
def handle_type(self, type_: type) -> QualifiedName: ...

@abc.abstractmethod
def handle_value(self, value: Any) -> Value:
...
def handle_value(self, value: Any) -> Value: ...

@abc.abstractmethod
def parse_args_str(self, args_str: str) -> list[Argument]:
...
def parse_args_str(self, args_str: str) -> list[Argument]: ...

@abc.abstractmethod
def parse_annotation_str(
self, annotation_str: str
) -> ResolvedType | InvalidExpression | Value:
...
) -> ResolvedType | InvalidExpression | Value: ...

@abc.abstractmethod
def parse_value_str(self, value: str) -> Value | InvalidExpression:
...
def parse_value_str(self, value: str) -> Value | InvalidExpression: ...

@abc.abstractmethod
def report_error(self, error: ParserError) -> None:
...
def report_error(self, error: ParserError) -> None: ...

@abc.abstractmethod
def finalize(self):
...
def finalize(self): ...
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black==22.8.0
black==26.1.0
flake8~=6.1.0
isort==5.10.1
numpy~=1.20
Expand Down
15 changes: 5 additions & 10 deletions tests/py-demo/demo/pure_python/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@ def foo():
return 42


def search(a: int, b: list[int]) -> int:
...
def search(a: int, b: list[int]) -> int: ...


def builtin_function_as_default_arg(func: type(len) = len):
...
def builtin_function_as_default_arg(func: type(len) = len): ...


def function_as_default_arg(func: type(search) = search):
...
def function_as_default_arg(func: type(search) = search): ...


def lambda_as_default_arg(callback=lambda val: 0):
...
def lambda_as_default_arg(callback=lambda val: 0): ...


def static_method_as_default_arg(callback=_Dummy.foo):
...
def static_method_as_default_arg(callback=_Dummy.foo): ...


def accept_frozenset(arg: typing.FrozenSet[int | float]) -> int | None:
Expand Down
3 changes: 1 addition & 2 deletions tests/py-demo/demo/pure_python/functions_3_8_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ def args_mix(
x: int = 1,
y=int,
**kwargs: typing.Dict[int, str],
):
...
): ...
3 changes: 1 addition & 2 deletions tests/py-demo/demo/pure_python/functions_3_9_plus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
def generic_alias_annotation(
a: list[tuple[int]],
b: dict[int, str],
) -> list[float]:
...
) -> list[float]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __all__: list[str] = ["Base", "CppException", "Derived", "Foo", "Outer"]
class Base:
class Inner:
pass

name: str

class CppException(Exception):
Expand Down Expand Up @@ -53,5 +54,7 @@ class Outer:
def name(self) -> str: ...
@property
def value(self) -> int: ...

value: Outer.Inner.NestedEnum

inner: Outer.Inner
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ __all__: list[str] = [
def accept_matrix_int(
arg0: typing.Annotated[
numpy.ndarray, numpy.int32, pybind11_stubgen.typing_ext.FixedSize(3, 3)
]
],
) -> None: ...
def accept_vector_float64(
arg0: typing.Annotated[
numpy.ndarray, numpy.float64, pybind11_stubgen.typing_ext.FixedSize(3, 1)
]
],
) -> None: ...
def dense_matrix_c(
arg0: typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", "n")
]
],
) -> typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", "n")
]: ...
def dense_matrix_r(
arg0: typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", "n")
]
],
) -> typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", "n")
]: ...
Expand All @@ -52,7 +52,7 @@ def fixed_mutator_a(
numpy.float32,
pybind11_stubgen.typing_ext.FixedSize(5, 6),
numpy.ndarray.flags.writeable,
]
],
) -> None: ...
def fixed_mutator_c(
arg0: typing.Annotated[
Expand All @@ -61,7 +61,7 @@ def fixed_mutator_c(
pybind11_stubgen.typing_ext.FixedSize(5, 6),
numpy.ndarray.flags.writeable,
numpy.ndarray.flags.f_contiguous,
]
],
) -> None: ...
def fixed_mutator_r(
arg0: typing.Annotated[
Expand All @@ -70,31 +70,35 @@ def fixed_mutator_r(
pybind11_stubgen.typing_ext.FixedSize(5, 6),
numpy.ndarray.flags.writeable,
numpy.ndarray.flags.c_contiguous,
]
],
) -> None: ...
def four_col_matrix_r(
arg0: typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", 4)
]
],
) -> typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize("m", 4)
]: ...
def four_row_matrix_r(
arg0: typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize(4, "n")
]
],
) -> typing.Annotated[
numpy.ndarray, numpy.float32, pybind11_stubgen.typing_ext.DynamicSize(4, "n")
]: ...
def get_matrix_int() -> typing.Annotated[
numpy.ndarray, numpy.int32, pybind11_stubgen.typing_ext.FixedSize(3, 3)
]: ...
def get_vector_float64() -> typing.Annotated[
numpy.ndarray, numpy.float64, pybind11_stubgen.typing_ext.FixedSize(3, 1)
]: ...
def get_matrix_int() -> (
typing.Annotated[
numpy.ndarray, numpy.int32, pybind11_stubgen.typing_ext.FixedSize(3, 3)
]
): ...
def get_vector_float64() -> (
typing.Annotated[
numpy.ndarray, numpy.float64, pybind11_stubgen.typing_ext.FixedSize(3, 1)
]
): ...
def sparse_matrix_c(
arg0: typing.Annotated[scipy.sparse.csc_matrix, numpy.float32]
arg0: typing.Annotated[scipy.sparse.csc_matrix, numpy.float32],
) -> typing.Annotated[scipy.sparse.csc_matrix, numpy.float32]: ...
def sparse_matrix_r(
arg0: typing.Annotated[scipy.sparse.csr_matrix, numpy.float32]
arg0: typing.Annotated[scipy.sparse.csr_matrix, numpy.float32],
) -> typing.Annotated[scipy.sparse.csr_matrix, numpy.float32]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ __all__: list[str] = [
]

def accept_ndarray_float64(
arg0: typing.Annotated[numpy.ndarray, numpy.float64]
arg0: typing.Annotated[numpy.ndarray, numpy.float64],
) -> None: ...
def accept_ndarray_int(arg0: typing.Annotated[numpy.ndarray, numpy.int32]) -> None: ...
def get_ndarray_float64() -> typing.Annotated[numpy.ndarray, numpy.float64]: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class WithGetterSetterDoc:
"""
getter doc token
"""

@def_property.setter
def def_property(self, arg1: int) -> None:
"""
setter doc token
"""

@property
def def_property_readonly(self) -> int:
"""
Expand All @@ -44,6 +46,7 @@ class WithPropAndGetterSetterDoc:
"""
prop doc token
"""

@def_property.setter
def def_property(self, arg1: int) -> None: ...
@property
Expand All @@ -64,23 +67,27 @@ class WithPropDoc:
"""
prop doc token
"""

@def_property.setter
def def_property(self, arg1: int) -> None: ...
@property
def def_property_readonly(self) -> int:
"""
prop doc token
"""

@property
def def_readonly(self) -> int:
"""
prop doc token
"""

@property
def def_readwrite(self) -> int:
"""
prop doc token
"""

@def_readwrite.setter
def def_readwrite(self, arg0: int) -> None: ...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ __all__: list[str] = [
]

def std_array(
arg0: typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(3)]
arg0: typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(3)],
) -> typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(3)]: ...
def std_map() -> dict[int, complex]: ...
def std_optional(arg0: int | None) -> None: ...
Expand Down
Loading