From a251317cc3431b899c4439cbfb12bdaed396bd19 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Mon, 4 Mar 2024 14:07:05 +0900 Subject: [PATCH] fix: Don't render pybind11 KeysView, ValuesView, ItemsView class defs --- pybind11_stubgen/__init__.py | 2 ++ pybind11_stubgen/parser/mixins/filter.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) 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