Skip to content

Commit 4faf9b2

Browse files
authored
Don't render pybind11 KeysView, ValuesView, ItemsView class definitions (#211)
Fixes #209
1 parent f783045 commit 4faf9b2

File tree

11 files changed

+100
-27
lines changed

11 files changed

+100
-27
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Setup Python
19-
uses: actions/setup-python@v4
19+
uses: actions/setup-python@v5
2020
with:
2121
python-version: '3.11'
2222
- name: Checkout
23-
uses: actions/checkout@v3
23+
uses: actions/checkout@v4
2424
- name: Install requirements
2525
run: pip install -r requirements-dev.txt
2626
- name: Run isort
@@ -65,15 +65,15 @@ jobs:
6565
pybind11-branch: "master"
6666
numpy-format: "numpy-array-use-type-var"
6767
steps:
68-
- uses: actions/checkout@v3
68+
- uses: actions/checkout@v4
6969

7070
- name: Setup Python ${{ matrix.python }}
71-
uses: actions/setup-python@v4
71+
uses: actions/setup-python@v5
7272
with:
7373
python-version: ${{ matrix.python }}
7474

7575
- name: Update CMake
76-
uses: jwlawson/actions-setup-cmake@v1.13
76+
uses: jwlawson/actions-setup-cmake@v1.14
7777

7878
- name: Setup annotations on Linux
7979
if: runner.os == 'Linux'
@@ -94,11 +94,11 @@ jobs:
9494
run: ./tests/check-demo-stubs-generation.sh --stubs-sub-dir "stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}/${{ matrix.numpy-format }}" --${{ matrix.numpy-format }}
9595

9696
- name: Archive patch
97-
uses: actions/upload-artifact@v3
97+
uses: actions/upload-artifact@v4
9898
if: failure()
9999
with:
100-
name: "python-${{ matrix.python }}-pybind-${{ matrix.pybind11-branch }}.patch"
101-
path: "./tests/stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}.patch"
100+
name: "python-${{ matrix.python }}-pybind-${{ matrix.pybind11-branch }}-${{ matrix.numpy-format }}.patch"
101+
path: "./tests/stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}/${{ matrix.numpy-format }}.patch"
102102
retention-days: 30
103103
if-no-files-found: ignore
104104

@@ -120,10 +120,10 @@ jobs:
120120
- "3.8"
121121
- "3.7"
122122
steps:
123-
- uses: actions/checkout@v3
123+
- uses: actions/checkout@v4
124124

125125
- name: Setup Python ${{ matrix.python }}
126-
uses: actions/setup-python@v4
126+
uses: actions/setup-python@v5
127127
with:
128128
python-version: ${{ matrix.python }}
129129

@@ -154,7 +154,7 @@ jobs:
154154
runs-on: ubuntu-latest
155155

156156
steps:
157-
- uses: actions/checkout@v3
157+
- uses: actions/checkout@v4
158158

159159
- name: Setup Python ${{ matrix.python }}
160160
uses: actions/setup-python@v2

pybind11_stubgen/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from pybind11_stubgen.parser.mixins.filter import (
2121
FilterClassMembers,
2222
FilterInvalidIdentifiers,
23+
FilterPybind11ViewClasses,
2324
FilterPybindInternals,
2425
FilterTypingModuleAttributes,
2526
)
@@ -273,6 +274,7 @@ class Parser(
273274
FixValueReprRandomAddress,
274275
FixRedundantBuiltinsAnnotation,
275276
FilterPybindInternals,
277+
FilterPybind11ViewClasses,
276278
FixRedundantMethodsFromBuiltinObject,
277279
RemoveSelfAnnotation,
278280
FixPybind11EnumStrDoc,

pybind11_stubgen/parser/mixins/filter.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,22 @@ def handle_class_member(
125125
self.report_error(InvalidIdentifierError(path[-1], path.parent))
126126
return None
127127
return super().handle_class_member(path, class_, obj)
128+
129+
130+
class FilterPybind11ViewClasses(IParser):
131+
def handle_module_member(
132+
self, path: QualifiedName, module: types.ModuleType, obj: Any
133+
) -> (
134+
Docstring | Import | Alias | Class | list[Function] | Attribute | Module | None
135+
):
136+
result = super().handle_module_member(path, module, obj)
137+
138+
if isinstance(result, Class) and str(result.name) in [
139+
"ItemsView",
140+
"KeysView",
141+
"ValuesView",
142+
]:
143+
# TODO: check obj is a subclass of pybind11_object
144+
return None
145+
146+
return result

tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/issues.pyi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ from __future__ import annotations
22

33
import typing
44

5-
__all__ = ["issue_51_catastrophic_regex", "issue_73_utf8_doc_chars"]
5+
__all__ = [
6+
"backslashes_should_be_escaped",
7+
"issue_51_catastrophic_regex",
8+
"issue_73_utf8_doc_chars",
9+
]
10+
11+
def backslashes_should_be_escaped() -> None:
12+
"""
13+
\\brief A brief description of this function.
14+
15+
A detailed description of this function.
16+
17+
Here's some reStructuredText: :math:`x = [x, y, \\theta]^T`
18+
"""
619

720
def issue_51_catastrophic_regex(arg0: int, arg1: int) -> None:
821
"""

tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/stl_bind.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class MapStringComplex:
2828
Return the canonical string representation of this map.
2929
"""
3030
def __setitem__(self, arg0: str, arg1: complex) -> None: ...
31-
def items(self) -> typing.ItemsView[str, complex]: ...
32-
def keys(self) -> typing.KeysView[str]: ...
33-
def values(self) -> typing.ValuesView[complex]: ...
31+
def items(self) -> typing.ItemsView: ...
32+
def keys(self) -> typing.KeysView: ...
33+
def values(self) -> typing.ValuesView: ...
3434

3535
class VectorPairStringDouble:
3636
__hash__: typing.ClassVar[None] = None

tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ from __future__ import annotations
22

33
import typing
44

5-
__all__ = ["issue_51_catastrophic_regex", "issue_73_utf8_doc_chars"]
5+
__all__ = [
6+
"backslashes_should_be_escaped",
7+
"issue_51_catastrophic_regex",
8+
"issue_73_utf8_doc_chars",
9+
]
10+
11+
def backslashes_should_be_escaped() -> None:
12+
"""
13+
\\brief A brief description of this function.
14+
15+
A detailed description of this function.
16+
17+
Here's some reStructuredText: :math:`x = [x, y, \\theta]^T`
18+
"""
619

720
def issue_51_catastrophic_regex(arg0: int, arg1: int) -> None:
821
"""

tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class MapStringComplex:
2828
Return the canonical string representation of this map.
2929
"""
3030
def __setitem__(self, arg0: str, arg1: complex) -> None: ...
31-
def items(self) -> typing.ItemsView[str, complex]: ...
32-
def keys(self) -> typing.KeysView[str]: ...
33-
def values(self) -> typing.ValuesView[complex]: ...
31+
def items(self) -> typing.ItemsView: ...
32+
def keys(self) -> typing.KeysView: ...
33+
def values(self) -> typing.ValuesView: ...
3434

3535
class VectorPairStringDouble:
3636
__hash__: typing.ClassVar[None] = None

tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ from __future__ import annotations
22

33
import typing
44

5-
__all__ = ["issue_51_catastrophic_regex", "issue_73_utf8_doc_chars"]
5+
__all__ = [
6+
"backslashes_should_be_escaped",
7+
"issue_51_catastrophic_regex",
8+
"issue_73_utf8_doc_chars",
9+
]
10+
11+
def backslashes_should_be_escaped() -> None:
12+
"""
13+
\\brief A brief description of this function.
14+
15+
A detailed description of this function.
16+
17+
Here's some reStructuredText: :math:`x = [x, y, \\theta]^T`
18+
"""
619

720
def issue_51_catastrophic_regex(arg0: int, arg1: int) -> None:
821
"""

tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/stl_bind.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class MapStringComplex:
2828
Return the canonical string representation of this map.
2929
"""
3030
def __setitem__(self, arg0: str, arg1: complex) -> None: ...
31-
def items(self) -> typing.ItemsView[str, complex]: ...
32-
def keys(self) -> typing.KeysView[str]: ...
33-
def values(self) -> typing.ValuesView[complex]: ...
31+
def items(self) -> typing.ItemsView: ...
32+
def keys(self) -> typing.KeysView: ...
33+
def values(self) -> typing.ValuesView: ...
3434

3535
class VectorPairStringDouble:
3636
__hash__: typing.ClassVar[None] = None

tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/issues.pyi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ from __future__ import annotations
22

33
import typing
44

5-
__all__ = ["issue_51_catastrophic_regex", "issue_73_utf8_doc_chars"]
5+
__all__ = [
6+
"backslashes_should_be_escaped",
7+
"issue_51_catastrophic_regex",
8+
"issue_73_utf8_doc_chars",
9+
]
10+
11+
def backslashes_should_be_escaped() -> None:
12+
"""
13+
\\brief A brief description of this function.
14+
15+
A detailed description of this function.
16+
17+
Here's some reStructuredText: :math:`x = [x, y, \\theta]^T`
18+
"""
619

720
def issue_51_catastrophic_regex(arg0: int, arg1: int) -> None:
821
"""

0 commit comments

Comments
 (0)