Skip to content

Commit f42d8f7

Browse files
authored
Merge pull request #9801 from tk0miya/docutils-0.18_traverse_2
Support docutils-0.18: Consume generator of Element.traverse()
2 parents 6564701 + 3f3de7d commit f42d8f7

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

sphinx/transforms/i18n.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
296296
lst.append(new)
297297

298298
is_autofootnote_ref = NodeMatcher(nodes.footnote_reference, auto=Any)
299-
old_foot_refs: List[nodes.footnote_reference] = node.traverse(is_autofootnote_ref)
300-
new_foot_refs: List[nodes.footnote_reference] = patch.traverse(is_autofootnote_ref)
301-
if len(list(old_foot_refs)) != len(list(new_foot_refs)):
299+
old_foot_refs: List[nodes.footnote_reference] = list(node.traverse(is_autofootnote_ref)) # NOQA
300+
new_foot_refs: List[nodes.footnote_reference] = list(patch.traverse(is_autofootnote_ref)) # NOQA
301+
if len(old_foot_refs) != len(new_foot_refs):
302302
old_foot_ref_rawsources = [ref.rawsource for ref in old_foot_refs]
303303
new_foot_ref_rawsources = [ref.rawsource for ref in new_foot_refs]
304304
logger.warning(__('inconsistent footnote references in translated message.' +
@@ -339,9 +339,9 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
339339
# * use translated refname for section refname.
340340
# * inline reference "`Python <...>`_" has no 'refname'.
341341
is_refnamed_ref = NodeMatcher(nodes.reference, refname=Any)
342-
old_refs: List[nodes.reference] = node.traverse(is_refnamed_ref)
343-
new_refs: List[nodes.reference] = patch.traverse(is_refnamed_ref)
344-
if len(list(old_refs)) != len(list(new_refs)):
342+
old_refs: List[nodes.reference] = list(node.traverse(is_refnamed_ref))
343+
new_refs: List[nodes.reference] = list(patch.traverse(is_refnamed_ref))
344+
if len(old_refs) != len(new_refs):
345345
old_ref_rawsources = [ref.rawsource for ref in old_refs]
346346
new_ref_rawsources = [ref.rawsource for ref in new_refs]
347347
logger.warning(__('inconsistent references in translated message.' +
@@ -366,10 +366,10 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
366366

367367
# refnamed footnote should use original 'ids'.
368368
is_refnamed_footnote_ref = NodeMatcher(nodes.footnote_reference, refname=Any)
369-
old_foot_refs = node.traverse(is_refnamed_footnote_ref)
370-
new_foot_refs = patch.traverse(is_refnamed_footnote_ref)
369+
old_foot_refs = list(node.traverse(is_refnamed_footnote_ref))
370+
new_foot_refs = list(patch.traverse(is_refnamed_footnote_ref))
371371
refname_ids_map: Dict[str, List[str]] = {}
372-
if len(list(old_foot_refs)) != len(list(new_foot_refs)):
372+
if len(old_foot_refs) != len(new_foot_refs):
373373
old_foot_ref_rawsources = [ref.rawsource for ref in old_foot_refs]
374374
new_foot_ref_rawsources = [ref.rawsource for ref in new_foot_refs]
375375
logger.warning(__('inconsistent footnote references in translated message.' +
@@ -385,10 +385,10 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
385385

386386
# citation should use original 'ids'.
387387
is_citation_ref = NodeMatcher(nodes.citation_reference, refname=Any)
388-
old_cite_refs: List[nodes.citation_reference] = node.traverse(is_citation_ref)
389-
new_cite_refs: List[nodes.citation_reference] = patch.traverse(is_citation_ref)
388+
old_cite_refs: List[nodes.citation_reference] = list(node.traverse(is_citation_ref)) # NOQA
389+
new_cite_refs: List[nodes.citation_reference] = list(patch.traverse(is_citation_ref)) # NOQA
390390
refname_ids_map = {}
391-
if len(list(old_cite_refs)) != len(list(new_cite_refs)):
391+
if len(old_cite_refs) != len(new_cite_refs):
392392
old_cite_ref_rawsources = [ref.rawsource for ref in old_cite_refs]
393393
new_cite_ref_rawsources = [ref.rawsource for ref in new_cite_refs]
394394
logger.warning(__('inconsistent citation references in translated message.' +
@@ -405,10 +405,10 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
405405
# Original pending_xref['reftarget'] contain not-translated
406406
# target name, new pending_xref must use original one.
407407
# This code restricts to change ref-targets in the translation.
408-
old_xrefs = node.traverse(addnodes.pending_xref)
409-
new_xrefs = patch.traverse(addnodes.pending_xref)
408+
old_xrefs = list(node.traverse(addnodes.pending_xref))
409+
new_xrefs = list(patch.traverse(addnodes.pending_xref))
410410
xref_reftarget_map = {}
411-
if len(list(old_xrefs)) != len(list(new_xrefs)):
411+
if len(old_xrefs) != len(new_xrefs):
412412
old_xref_rawsources = [xref.rawsource for xref in old_xrefs]
413413
new_xref_rawsources = [xref.rawsource for xref in new_xrefs]
414414
logger.warning(__('inconsistent term references in translated message.' +

0 commit comments

Comments
 (0)