Skip to content

Commit

Permalink
Not very nice hack to force default documenter when generating table …
Browse files Browse the repository at this point in the history
…of contents

The overload documenter doesn't play nice here
  • Loading branch information
nyalldawson committed Sep 11, 2024
1 parent 18bda83 commit 53ebd18
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions autoautosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
from docutils import nodes
from docutils.parsers.rst import directives
from sphinx.ext import autosummary
from sphinx.ext.autosummary import Autosummary, ImportExceptionGroup, get_documenter
from sphinx.ext.autodoc import MethodDocumenter
from sphinx.ext.autosummary import Autosummary, ImportExceptionGroup
from sphinx.locale import __
from sphinx.util import logging
from sphinx.util.inspect import isstaticmethod, safe_getattr

from process_links import OverloadedPythonMethodDocumenter

# from sphinx.directives import directive
logger = logging.getLogger(__name__)

Expand All @@ -34,6 +37,21 @@ def new_extract_summary(doc: list[str], document: Any) -> str:

autosummary.extract_summary = new_extract_summary

old_get_documenter = autosummary.get_documenter


def new_get_documenter(app, obj: Any, parent: Any):
res = old_get_documenter(app, obj, parent)
if issubclass(res, OverloadedPythonMethodDocumenter):
# sorry, gross hack! OverloadedPythonMethodDocumenter works well
# for generating the actual docs, but fails when we are building
# the table of contents. So fallback to original class instead...
return MethodDocumenter
return res


autosummary.get_documenter = new_get_documenter


class AutoAutoSummary(Autosummary):
"""
Expand Down Expand Up @@ -100,7 +118,7 @@ def get_members(
continue
try:
chobj = safe_getattr(obj, name)
documenter = get_documenter(doc.settings.env.app, chobj, obj)
documenter = autosummary.get_documenter(doc.settings.env.app, chobj, obj)
# cl = get_class_that_defined_method(chobj)
# print(name, chobj.__qualname__, type(chobj), issubclass(chobj, Enum), documenter.objtype)
if documenter.objtype == typ:
Expand Down

0 comments on commit 53ebd18

Please sign in to comment.