Skip to content

Commit

Permalink
Do not re-assign nodes variable in renderer/sphinxrenderer.py (#938)
Browse files Browse the repository at this point in the history
The nodes variable is a global imported from docutils. Re-assigning this
variable leads to unpredictabe behavior. To avoid this, we simply rename
all occurrences of variable assignments to nodes_ instead.
  • Loading branch information
RaumZeit authored Jul 30, 2024
1 parent 6c8f9de commit b483706
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def run_directive(
_debug_indent += 1

self.nesting_level += 1
nodes = directive.run()
nodes_ = directive.run()
self.nesting_level -= 1

# TODO: the directive_args seems to be reused between different run_directives
Expand All @@ -631,17 +631,17 @@ def run_directive(
# In some cases of errors with a declaration there are no nodes
# (e.g., variable in function), so perhaps skip (see #671).
# If there are nodes, there should be at least 2.
if len(nodes) != 0:
assert len(nodes) >= 2, nodes
rst_node = nodes[1]
if len(nodes_) != 0:
assert len(nodes_) >= 2, nodes_
rst_node = nodes_[1]
finder = NodeFinder(rst_node.document)
rst_node.walk(finder)

signode = finder.declarator

if self.context.child:
signode.children = [n for n in signode.children if not n.tagname == "desc_addname"]
return nodes
return nodes_

def handle_declaration(
self,
Expand Down Expand Up @@ -806,8 +806,8 @@ def get_fully_qualified_name(self):
def create_template_prefix(self, decl) -> str:
if not decl.templateparamlist:
return ""
nodes = self.render(decl.templateparamlist)
return "template<" + "".join(n.astext() for n in nodes) + ">"
nodes_ = self.render(decl.templateparamlist)
return "template<" + "".join(n.astext() for n in nodes_) + ">"

def run_domain_directive(self, kind, names):
domain_directive = DomainDirectiveFactory.create(
Expand All @@ -828,21 +828,21 @@ def run_domain_directive(self, kind, names):
)
_debug_indent += 1

nodes = domain_directive.run()
nodes_ = domain_directive.run()

if config.breathe_debug_trace_directives:
_debug_indent -= 1

# Filter out outer class names if we are rendering a member as a part of a class content.
rst_node = nodes[1]
rst_node = nodes_[1]
finder = NodeFinder(rst_node.document)
rst_node.walk(finder)

signode = finder.declarator

if len(names) > 0 and self.context.child:
signode.children = [n for n in signode.children if not n.tagname == "desc_addname"]
return nodes
return nodes_

def create_doxygen_target(self, node):
"""Can be overridden to create a target node which uses the doxygen refid information
Expand Down Expand Up @@ -926,15 +926,15 @@ def render_declaration(self, node, declaration=None, description=None, **kwargs)
obj_type = kwargs.get("objtype", None)
if obj_type is None:
obj_type = node.kind
nodes = self.run_domain_directive(obj_type, [declaration.replace("\n", " ")])
nodes_ = self.run_domain_directive(obj_type, [declaration.replace("\n", " ")])
if self.app.env.config.breathe_debug_trace_doxygen_ids:
target = self.create_doxygen_target(node)
if len(target) == 0:
print("{}Doxygen target (old): (none)".format(" " * _debug_indent))
else:
print("{}Doxygen target (old): {}".format(" " * _debug_indent, target[0]["ids"]))

rst_node = nodes[1]
rst_node = nodes_[1]
finder = NodeFinder(rst_node.document)
rst_node.walk(finder)

Expand All @@ -950,7 +950,7 @@ def render_declaration(self, node, declaration=None, description=None, **kwargs)
target = self.create_doxygen_target(node)
signode.insert(0, target)
contentnode.extend(description)
return nodes
return nodes_

def visit_doxygen(self, node) -> List[Node]:
nodelist: List[Node] = []
Expand Down Expand Up @@ -989,8 +989,8 @@ def content(contentnode):
rendered_data = self.render(file_data, parent_context)
contentnode.extend(rendered_data)

nodes = self.handle_declaration(nodeDef, declaration, content_callback=content)
return nodes
nodes_ = self.handle_declaration(nodeDef, declaration, content_callback=content)
return nodes_

def visit_class(self, node) -> List[Node]:
# Read in the corresponding xml file and process
Expand Down Expand Up @@ -1047,16 +1047,16 @@ def content(contentnode) -> None:

assert kind in ("class", "struct", "interface")
display_obj_type = "interface" if kind == "interface" else None
nodes = self.handle_declaration(
nodes_ = self.handle_declaration(
nodeDef, declaration, content_callback=content, display_obj_type=display_obj_type
)
if "members-only" in self.context.directive_args[2]:
assert len(nodes) >= 2
assert isinstance(nodes[1], addnodes.desc)
assert len(nodes[1]) >= 2
assert isinstance(nodes[1][1], addnodes.desc_content)
return nodes[1][1].children
return nodes
assert len(nodes_) >= 2
assert isinstance(nodes_[1], addnodes.desc)
assert len(nodes_[1]) >= 2
assert isinstance(nodes_[1][1], addnodes.desc_content)
return nodes_[1][1].children
return nodes_

def visit_namespace(self, node) -> List[Node]:
# Read in the corresponding xml file and process
Expand Down Expand Up @@ -1087,10 +1087,10 @@ def content(contentnode):
contentnode.extend(rendered_data)

display_obj_type = "namespace" if self.get_domain() != "py" else "module"
nodes = self.handle_declaration(
nodes_ = self.handle_declaration(
nodeDef, declaration, content_callback=content, display_obj_type=display_obj_type
)
return nodes
return nodes_

def visit_compound(self, node, render_empty_node=True, **kwargs) -> List[Node]:
# Read in the corresponding xml file and process
Expand Down Expand Up @@ -1144,8 +1144,8 @@ def render_signature(file_data, doxygen_target, name, kind):

self.context.directive_args[1] = [arg]

nodes = self.run_domain_directive(kind, self.context.directive_args[1])
rst_node = nodes[1]
nodes_ = self.run_domain_directive(kind, self.context.directive_args[1])
rst_node = nodes_[1]

finder = NodeFinder(rst_node.document)
rst_node.walk(finder)
Expand All @@ -1156,14 +1156,14 @@ def render_signature(file_data, doxygen_target, name, kind):
finder.declarator[0] = addnodes.desc_annotation(kind + " ", kind + " ")

rst_node.children[0].insert(0, doxygen_target)
return nodes, finder.content
return nodes_, finder.content

refid = self.get_refid(node.refid)
render_sig = kwargs.get("render_signature", render_signature)
with WithContext(self, new_context):
# Pretend that the signature is being rendered in context of the
# definition, for proper domain detection
nodes, contentnode = render_sig(
nodes_, contentnode = render_sig(
file_data, self.target_handler.create_target(refid), name, kind
)

Expand All @@ -1172,7 +1172,7 @@ def render_signature(file_data, doxygen_target, name, kind):
contentnode.extend(self.render(include, new_context.create_child_context(include)))

contentnode.extend(rendered_data)
return nodes
return nodes_

def visit_file(self, node) -> List[Node]:
def render_signature(file_data, doxygen_target, name, kind):
Expand Down Expand Up @@ -1964,8 +1964,8 @@ def visit_function(self, node) -> List[Node]:
elements.append(name)
elements.append(node.get_argsstring())
declaration = " ".join(elements)
nodes = self.handle_declaration(node, declaration)
return nodes
nodes_ = self.handle_declaration(node, declaration)
return nodes_
else:
# Get full function signature for the domain directive.
param_list = []
Expand Down Expand Up @@ -2000,7 +2000,7 @@ def visit_function(self, node) -> List[Node]:
self.context = cast(RenderContext, self.context)
self.context.directive_args[1] = [signature]

nodes = self.run_domain_directive(node.kind, self.context.directive_args[1])
nodes_ = self.run_domain_directive(node.kind, self.context.directive_args[1])

assert self.app.env is not None
if self.app.env.config.breathe_debug_trace_doxygen_ids:
Expand All @@ -2012,7 +2012,7 @@ def visit_function(self, node) -> List[Node]:
"{}Doxygen target (old): {}".format(" " * _debug_indent, target[0]["ids"])
)

rst_node = nodes[1]
rst_node = nodes_[1]
finder = NodeFinder(rst_node.document)
rst_node.walk(finder)

Expand All @@ -2023,7 +2023,7 @@ def visit_function(self, node) -> List[Node]:
rst_node.children[0].insert(0, target)

finder.content.extend(self.description(node))
return nodes
return nodes_

def visit_define(self, node) -> List[Node]:
declaration = node.name
Expand Down

0 comments on commit b483706

Please sign in to comment.