sphinxext: Fix duplicated output in FunctionDocumenter
Sphinx calls get_doc() multiple times per documenter: once in _generate() to check for mocked objects, once from _find_signature() during format_signature(), and once from add_content(). The DocstringSignatureMixin base class caches the result of the first call in _new_docstrings, so subsequent calls to super().get_doc() return the same already-mutated list. document_function() mutates its docstrings argument in-place, injecting type fields and prepending code sample blocks. Each additional call to FunctionDocumenter.get_doc() passed the already-mutated cached list back through document_function(), compounding the mutations and producing duplicated parameter samples, return samples, and return type entries in the rendered output. Fix by caching the result of document_function() in _wsme_docstrings and returning it directly on subsequent calls, so document_function() is only invoked once per documenter instance. Change-Id: I6be82d451c3ec9aa7bf3e04cdd2642778c98da84 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
400865c556
commit
5abd6c3f5c
@@ -519,15 +519,19 @@ class FunctionDocumenter(autodoc.MethodDocumenter):
|
||||
def get_doc(self):
|
||||
"""Inject the type and param fields into the docstrings so that the
|
||||
user can add its own param fields to document the parameters"""
|
||||
if hasattr(self, '_wsme_docstrings'):
|
||||
return self._wsme_docstrings
|
||||
|
||||
docstrings = super().get_doc()
|
||||
|
||||
protocols = get_protocols(
|
||||
self.options.protocols or self.env.app.config.wsme_protocols
|
||||
)
|
||||
|
||||
return document_function(
|
||||
self._wsme_docstrings = document_function(
|
||||
self.wsme_fd, docstrings, protocols
|
||||
)
|
||||
return self._wsme_docstrings
|
||||
|
||||
def add_content(self, more_content):
|
||||
super(FunctionDocumenter, self).add_content(more_content)
|
||||
|
||||
Reference in New Issue
Block a user