diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4778517..46b8080 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,11 +16,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install requirements run: pip install -r requirements-dev.txt - name: Run isort @@ -65,15 +65,15 @@ jobs: pybind11-branch: "master" numpy-format: "numpy-array-use-type-var" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 + uses: jwlawson/actions-setup-cmake@v1.14 - name: Setup annotations on Linux if: runner.os == 'Linux' @@ -94,11 +94,11 @@ jobs: run: ./tests/check-demo-stubs-generation.sh --stubs-sub-dir "stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}/${{ matrix.numpy-format }}" --${{ matrix.numpy-format }} - name: Archive patch - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() with: - name: "python-${{ matrix.python }}-pybind-${{ matrix.pybind11-branch }}.patch" - path: "./tests/stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}.patch" + name: "python-${{ matrix.python }}-pybind-${{ matrix.pybind11-branch }}-${{ matrix.numpy-format }}.patch" + path: "./tests/stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}/${{ matrix.numpy-format }}.patch" retention-days: 30 if-no-files-found: ignore @@ -120,10 +120,10 @@ jobs: - "3.8" - "3.7" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} @@ -154,7 +154,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python }} uses: actions/setup-python@v2 diff --git a/pybind11_stubgen/__init__.py b/pybind11_stubgen/__init__.py index 2de7f21..f3a9215 100644 --- a/pybind11_stubgen/__init__.py +++ b/pybind11_stubgen/__init__.py @@ -20,6 +20,7 @@ from pybind11_stubgen.parser.mixins.filter import ( FilterClassMembers, FilterInvalidIdentifiers, + FilterPybind11ViewClasses, FilterPybindInternals, FilterTypingModuleAttributes, ) @@ -273,6 +274,7 @@ class Parser( FixValueReprRandomAddress, FixRedundantBuiltinsAnnotation, FilterPybindInternals, + FilterPybind11ViewClasses, FixRedundantMethodsFromBuiltinObject, RemoveSelfAnnotation, FixPybind11EnumStrDoc, diff --git a/pybind11_stubgen/parser/mixins/filter.py b/pybind11_stubgen/parser/mixins/filter.py index 424752f..c011293 100644 --- a/pybind11_stubgen/parser/mixins/filter.py +++ b/pybind11_stubgen/parser/mixins/filter.py @@ -125,3 +125,22 @@ def handle_class_member( self.report_error(InvalidIdentifierError(path[-1], path.parent)) return None return super().handle_class_member(path, class_, obj) + + +class FilterPybind11ViewClasses(IParser): + def handle_module_member( + self, path: QualifiedName, module: types.ModuleType, obj: Any + ) -> ( + Docstring | Import | Alias | Class | list[Function] | Attribute | Module | None + ): + result = super().handle_module_member(path, module, obj) + + if isinstance(result, Class) and str(result.name) in [ + "ItemsView", + "KeysView", + "ValuesView", + ]: + # TODO: check obj is a subclass of pybind11_object + return None + + return result diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/issues.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/issues.pyi index 09af4e4..09cc9d0 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/issues.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/issues.pyi @@ -2,7 +2,20 @@ from __future__ import annotations import typing -__all__ = ["issue_51_catastrophic_regex", "issue_73_utf8_doc_chars"] +__all__ = [ + "backslashes_should_be_escaped", + "issue_51_catastrophic_regex", + "issue_73_utf8_doc_chars", +] + +def backslashes_should_be_escaped() -> None: + """ + \\brief A brief description of this function. + + A detailed description of this function. + + Here's some reStructuredText: :math:`x = [x, y, \\theta]^T` + """ def issue_51_catastrophic_regex(arg0: int, arg1: int) -> None: """ diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/stl_bind.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/stl_bind.pyi index c39135b..3362b98 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/stl_bind.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/stl_bind.pyi @@ -28,9 +28,9 @@ class MapStringComplex: Return the canonical string representation of this map. """ def __setitem__(self, arg0: str, arg1: complex) -> None: ... - def items(self) -> typing.ItemsView[str, complex]: ... - def keys(self) -> typing.KeysView[str]: ... - def values(self) -> typing.ValuesView[complex]: ... + def items(self) -> typing.ItemsView: ... + def keys(self) -> typing.KeysView: ... + def values(self) -> typing.ValuesView: ... class VectorPairStringDouble: __hash__: typing.ClassVar[None] = None diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi index 09af4e4..09cc9d0 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi @@ -2,7 +2,20 @@ from __future__ import annotations import typing -__all__ = ["issue_51_catastrophic_regex", "issue_73_utf8_doc_chars"] +__all__ = [ + "backslashes_should_be_escaped", + "issue_51_catastrophic_regex", + "issue_73_utf8_doc_chars", +] + +def backslashes_should_be_escaped() -> None: + """ + \\brief A brief description of this function. + + A detailed description of this function. + + Here's some reStructuredText: :math:`x = [x, y, \\theta]^T` + """ def issue_51_catastrophic_regex(arg0: int, arg1: int) -> None: """ diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi index c39135b..3362b98 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi @@ -28,9 +28,9 @@ class MapStringComplex: Return the canonical string representation of this map. """ def __setitem__(self, arg0: str, arg1: complex) -> None: ... - def items(self) -> typing.ItemsView[str, complex]: ... - def keys(self) -> typing.KeysView[str]: ... - def values(self) -> typing.ValuesView[complex]: ... + def items(self) -> typing.ItemsView: ... + def keys(self) -> typing.KeysView: ... + def values(self) -> typing.ValuesView: ... class VectorPairStringDouble: __hash__: typing.ClassVar[None] = None diff --git a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi index 09af4e4..09cc9d0 100644 --- a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi +++ b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi @@ -2,7 +2,20 @@ from __future__ import annotations import typing -__all__ = ["issue_51_catastrophic_regex", "issue_73_utf8_doc_chars"] +__all__ = [ + "backslashes_should_be_escaped", + "issue_51_catastrophic_regex", + "issue_73_utf8_doc_chars", +] + +def backslashes_should_be_escaped() -> None: + """ + \\brief A brief description of this function. + + A detailed description of this function. + + Here's some reStructuredText: :math:`x = [x, y, \\theta]^T` + """ def issue_51_catastrophic_regex(arg0: int, arg1: int) -> None: """ diff --git a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi index c39135b..3362b98 100644 --- a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi +++ b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi @@ -28,9 +28,9 @@ class MapStringComplex: Return the canonical string representation of this map. """ def __setitem__(self, arg0: str, arg1: complex) -> None: ... - def items(self) -> typing.ItemsView[str, complex]: ... - def keys(self) -> typing.KeysView[str]: ... - def values(self) -> typing.ValuesView[complex]: ... + def items(self) -> typing.ItemsView: ... + def keys(self) -> typing.KeysView: ... + def values(self) -> typing.ValuesView: ... class VectorPairStringDouble: __hash__: typing.ClassVar[None] = None diff --git a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi index 09af4e4..09cc9d0 100644 --- a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi +++ b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi @@ -2,7 +2,20 @@ from __future__ import annotations import typing -__all__ = ["issue_51_catastrophic_regex", "issue_73_utf8_doc_chars"] +__all__ = [ + "backslashes_should_be_escaped", + "issue_51_catastrophic_regex", + "issue_73_utf8_doc_chars", +] + +def backslashes_should_be_escaped() -> None: + """ + \\brief A brief description of this function. + + A detailed description of this function. + + Here's some reStructuredText: :math:`x = [x, y, \\theta]^T` + """ def issue_51_catastrophic_regex(arg0: int, arg1: int) -> None: """ diff --git a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi index c39135b..3362b98 100644 --- a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi +++ b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi @@ -28,9 +28,9 @@ class MapStringComplex: Return the canonical string representation of this map. """ def __setitem__(self, arg0: str, arg1: complex) -> None: ... - def items(self) -> typing.ItemsView[str, complex]: ... - def keys(self) -> typing.KeysView[str]: ... - def values(self) -> typing.ValuesView[complex]: ... + def items(self) -> typing.ItemsView: ... + def keys(self) -> typing.KeysView: ... + def values(self) -> typing.ValuesView: ... class VectorPairStringDouble: __hash__: typing.ClassVar[None] = None