Skip to content

Commit

Permalink
Don't render pybind11 KeysView, ValuesView, ItemsView class definitio…
Browse files Browse the repository at this point in the history
…ns (#211)

Fixes #209
  • Loading branch information
sizmailov authored Mar 4, 2024
1 parent f783045 commit 4faf9b2
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 27 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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

Expand All @@ -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 }}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pybind11_stubgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from pybind11_stubgen.parser.mixins.filter import (
FilterClassMembers,
FilterInvalidIdentifiers,
FilterPybind11ViewClasses,
FilterPybindInternals,
FilterTypingModuleAttributes,
)
Expand Down Expand Up @@ -273,6 +274,7 @@ class Parser(
FixValueReprRandomAddress,
FixRedundantBuiltinsAnnotation,
FilterPybindInternals,
FilterPybind11ViewClasses,
FixRedundantMethodsFromBuiltinObject,
RemoveSelfAnnotation,
FixPybind11EnumStrDoc,
Expand Down
19 changes: 19 additions & 0 deletions pybind11_stubgen/parser/mixins/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4faf9b2

Please sign in to comment.