Skip to content

Commit

Permalink
Strip argument names from method summary in TOC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nyalldawson committed Aug 8, 2024
1 parent 15cec98 commit 813fa30
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions autoautosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 __
Expand All @@ -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).
Expand Down

0 comments on commit 813fa30

Please sign in to comment.