From f97094fb239bc6c25ae841d1166dba2698b5a289 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 11 Aug 2026 15:38:03 +0100 Subject: [PATCH] Don't include swig static member function wrappers in stubs --- docs/conf.py | 10 +++++++++- docs/stubgen.py | 15 ++++++++++++--- docs/verify-docstrings.py | 12 ++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 87de0eb87..3ed78f8d3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,6 +24,7 @@ import datetime #sys.path.insert(0, os.path.abspath('.')) import struct +import inspect # path to module libraries for windows if struct.calcsize("P") == 8: @@ -481,10 +482,17 @@ def build_finished(app, exception): module = sys.modules[module_name] entries = dir(module) for item in dir(module): + if '_' in item: + segments = item.split("_") + if hasattr(module, segments[0]) and inspect.isclass( + getattr(module, segments[0]) + ): + continue + if 'INTERNAL:' not in str(module.__dict__[item].__doc__): items.append('{}.{}'.format(module_name, item)) - items = set(filter(lambda i: re.search('__|SWIG|ResourceId_Null|rdcfixedarray_of|rdcarray_of|Structured.*List', i) is None, items)) + items = set(filter(lambda i: re.search('__|SWIG|rdcfixedarray_of|rdcarray_of|Structured.*List', i) is None, items)) # Remove any documented/indexed python objects items -= set(objs.keys()) diff --git a/docs/stubgen.py b/docs/stubgen.py index d34fdd3c7..af547d9a5 100644 --- a/docs/stubgen.py +++ b/docs/stubgen.py @@ -113,7 +113,7 @@ def process_annotation(context: Any, deps: Optional[List[str]], annot: str) -> s locals.update(sys.modules) while True: try: - from typing import ForwardRef, evaluate_forward_ref # type: ignore + from typing import ForwardRef, evaluate_forward_ref # type: ignore dep_type = evaluate_forward_ref( ForwardRef(annot), globals=globals(), locals=locals @@ -527,7 +527,9 @@ def gen_class(file: Stream, class_obj: Type): elif inspect.isgetsetdescriptor(item): doc = TYPE_PATTERN.search(item.__doc__) if doc is None: - raise ValueError("Didn't find type pattern in docstring") + raise ValueError( + f"Didn't find type pattern in docstring for {item.__name__}" + ) type_str = doc[1] if type_str != class_obj.__name__: @@ -620,6 +622,13 @@ def gen(module: types.ModuleType, destpath: str): if shouldskip(item_name): continue + if "_" in item_name: + segments = item_name.split("_") + if hasattr(module, segments[0]) and inspect.isclass( + getattr(module, segments[0]) + ): + continue + item = getattr(module, item_name) if inspect.isclass(item): @@ -651,7 +660,7 @@ def gen(module: types.ModuleType, destpath: str): deps = [] - match: re.Match[str] = RTYPE_PATTERN.search(func_doc) + match: Optional[re.Match[str]] = RTYPE_PATTERN.search(func_doc) if match is not None: add_dependencies(item, deps, match[1]) ret = f" -> {unqualify(item, match[1])}" diff --git a/docs/verify-docstrings.py b/docs/verify-docstrings.py index 7b3d86088..5198a0fc6 100644 --- a/docs/verify-docstrings.py +++ b/docs/verify-docstrings.py @@ -172,6 +172,7 @@ def check_function(parent_name, objname, obj, source, global_func, typelist): default_val = p[2].lstrip() if len(default_val) > 0 and default_val[0] == '=': default_val = make_c_typeval(default_val[1:].strip(), False, typelist) + default_val = default_val.replace('(', '\\(').replace(')', '\\)') funcargs[0] += make_c_typeval(p[0], True, typelist) + ' ?' + p[1] funcargs[1] += make_c_typeval(p[0], False, typelist) + ' ' + p[1] @@ -262,9 +263,16 @@ for mod_name in check_mods: if args.verbose: print("===== Checks for {} =====".format(mod_name)) for objname in dir(mod): - if re.search('__|SWIG|ResourceId_Null|rdcarray_of|Structured.*List', objname): + if re.search('__|SWIG|rdcarray_of|Structured.*List', objname): continue + if "_" in objname: + segments = objname.split("_") + if hasattr(mod, segments[0]) and inspect.isclass( + getattr(mod, segments[0]) + ): + continue + # skip some functions that have special bindings and won't be easily found if objname in ['CreateRemoteServerConnection', 'DumpObject', 'GetSupportedDeviceProtocols']: if args.verbose: @@ -380,7 +388,7 @@ for mod_name in check_mods: print("Skipping {}.{}".format(objname, member_name)) continue - if callable(member): + if callable(member) or inspect.ismethoddescriptor(member): used_types = [] check_function(qualname, member_name, member, source, False, used_types)