From af47e417fb05690bca259a185443ce0ee5883294 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 7 Aug 2024 15:22:44 +1000 Subject: [PATCH] Strip `argument` names from method summary in TOC Eg don't use "Returns value at the specified `index`" in the TOC, as there's no indication what `index` is. Instead strip the ` so that index just appears as a normal string. --- autoautosummary.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/autoautosummary.py b/autoautosummary.py index 5198047802ae..2e9ec0f595b0 100644 --- a/autoautosummary.py +++ b/autoautosummary.py @@ -3,12 +3,14 @@ # added toctree and nosignatures in options from enum import Enum +import re from typing import Any, List, Optional import PyQt5 from docutils import nodes from docutils.parsers.rst import directives from sphinx.ext.autosummary import Autosummary, get_documenter +from sphinx.ext import autosummary from sphinx.util.inspect import safe_getattr from sphinx.util import logging from sphinx.locale import __ @@ -17,6 +19,16 @@ logger = logging.getLogger(__name__) +old_extract_summary = autosummary.extract_summary + +def new_extract_summary(doc: list[str], document: Any) -> str: + res = old_extract_summary(doc, document) + res = re.sub(r'\`((?!(?:None|True|False))[a-zA-Z0-9_]+)\`', r'\1', res) + return res + +autosummary.extract_summary = new_extract_summary + + class AutoAutoSummary(Autosummary): """ Create a summary for methods, attributes and signals (autosummary).