From b3e0170ab546a96930ce3114b0a1a560953c0ff4 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 1 Aug 2023 21:22:53 +0100 Subject: [PATCH] Fixed #34756 -- Fixed docs HTML build on Sphinx 7.1+. --- docs/_ext/djangodocs.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py index 866b8f891d..7d55cb0333 100644 --- a/docs/_ext/djangodocs.py +++ b/docs/_ext/djangodocs.py @@ -9,6 +9,7 @@ from docutils import nodes from docutils.parsers.rst import Directive from docutils.statemachine import ViewList from sphinx import addnodes +from sphinx import version_info as sphinx_version from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.directives.code import CodeBlock from sphinx.domains.std import Cmdoption @@ -127,12 +128,23 @@ class DjangoHTMLTranslator(HTMLTranslator): def visit_desc_parameterlist(self, node): self.body.append("(") # by default sphinx puts around the "(" - self.first_param = 1 self.optional_param_level = 0 self.param_separator = node.child_text_separator - self.required_params_left = sum( + # Counts 'parameter groups' being either a required parameter, or a set + # of contiguous optional ones. + required_params = [ isinstance(c, addnodes.desc_parameter) for c in node.children - ) + ] + # How many required parameters are left. + self.required_params_left = sum(required_params) + if sphinx_version < (7, 1): + self.first_param = 1 + else: + self.is_first_param = True + self.params_left_at_level = 0 + self.param_group_index = 0 + self.list_is_required_param = required_params + self.multi_line_parameter_list = False def depart_desc_parameterlist(self, node): self.body.append(")")