summaryrefslogtreecommitdiff
path: root/sphinx/util/nodes.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-10-27 01:49:57 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-10-27 01:49:59 +0900
commit13803a79e7179f40a27f46d5a5a05f1eebbcbb63 (patch)
tree2cb19dd2900c96c57f601d46bdfbfc0652127b13 /sphinx/util/nodes.py
parent2be9d6b092965a2f9354da66b645bf5ea76ce288 (diff)
downloadsphinx-git-13803a79e7179f40a27f46d5a5a05f1eebbcbb63.tar.gz
Support docutils-0.18: Consume iterator of Element.traverse()
Since 0.18, Element.traverse() returns an iterator instead of intermediate object. As a result, the return value is always considered as truthy value. And it becomes fragile when the caller modifies the doctree on the loop.
Diffstat (limited to 'sphinx/util/nodes.py')
-rw-r--r--sphinx/util/nodes.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index 78663e4c7..bc16e44c1 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -343,7 +343,7 @@ def clean_astext(node: Element) -> str:
node = node.deepcopy()
for img in node.traverse(nodes.image):
img['alt'] = ''
- for raw in node.traverse(nodes.raw):
+ for raw in list(node.traverse(nodes.raw)):
raw.parent.remove(raw)
return node.astext()
@@ -408,7 +408,7 @@ def inline_all_toctrees(builder: "Builder", docnameset: Set[str], docname: str,
Record all docnames in *docnameset*, and output docnames with *colorfunc*.
"""
tree = cast(nodes.document, tree.deepcopy())
- for toctreenode in tree.traverse(addnodes.toctree):
+ for toctreenode in list(tree.traverse(addnodes.toctree)):
newnodes = []
includefiles = map(str, toctreenode['includefiles'])
for includefile in includefiles: