From 8113d9d89aad626a30508c7c849c926c1cd3b2f7 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 27 Aug 2024 15:44:51 +1000 Subject: [PATCH] Silence a noisy warning when building docs autosummary fails to import class attributes exposed by sip, which results in thousands of warnings dumped during the doc build. Hack around this, so that we only get valid warnings when building docs --- autoautosummary.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/autoautosummary.py b/autoautosummary.py index aeee46fa13b1..0d0f64fa7834 100644 --- a/autoautosummary.py +++ b/autoautosummary.py @@ -10,7 +10,7 @@ from docutils import nodes from docutils.parsers.rst import directives from sphinx.ext import autosummary -from sphinx.ext.autosummary import Autosummary, get_documenter +from sphinx.ext.autosummary import Autosummary, ImportExceptionGroup, get_documenter from sphinx.locale import __ from sphinx.util import logging from sphinx.util.inspect import isstaticmethod, safe_getattr @@ -140,6 +140,28 @@ def get_members( print(str(e)) raise e + def import_by_name( + self, + name: str, + prefixes: list[str | None], + ) -> tuple[str, Any, Any, str]: + """ + We have to wrap the original import_by_name, which raises noisy + exceptions when trying to handle class attributes exposed by SIP. + """ + try: + res = super().import_by_name(name, prefixes) + except ImportExceptionGroup: + # class attribute import failed, just handle this by faking + # the results. The resultant documentation still correctly + # contains the attribute docstrings... + name_parts = name.split(".") + parent_name = ".".join(name_parts[:-1]) + parent_res = super().import_by_name(parent_name, prefixes) + res = (name, None, parent_res[2], parent_res[3]) + + return res + def run(self): clazz = self.arguments[0] rubric_title = None