diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py index 3145379cb..d28376bec 100644 --- a/sphinx/transforms/i18n.py +++ b/sphinx/transforms/i18n.py @@ -298,7 +298,7 @@ class Locale(SphinxTransform): is_autofootnote_ref = NodeMatcher(nodes.footnote_reference, auto=Any) old_foot_refs: List[nodes.footnote_reference] = node.traverse(is_autofootnote_ref) new_foot_refs: List[nodes.footnote_reference] = patch.traverse(is_autofootnote_ref) - if len(old_foot_refs) != len(new_foot_refs): + if len(list(old_foot_refs)) != len(list(new_foot_refs)): old_foot_ref_rawsources = [ref.rawsource for ref in old_foot_refs] new_foot_ref_rawsources = [ref.rawsource for ref in new_foot_refs] logger.warning(__('inconsistent footnote references in translated message.' + @@ -341,7 +341,7 @@ class Locale(SphinxTransform): is_refnamed_ref = NodeMatcher(nodes.reference, refname=Any) old_refs: List[nodes.reference] = node.traverse(is_refnamed_ref) new_refs: List[nodes.reference] = patch.traverse(is_refnamed_ref) - if len(old_refs) != len(new_refs): + if len(list(old_refs)) != len(list(new_refs)): old_ref_rawsources = [ref.rawsource for ref in old_refs] new_ref_rawsources = [ref.rawsource for ref in new_refs] logger.warning(__('inconsistent references in translated message.' + @@ -369,7 +369,7 @@ class Locale(SphinxTransform): old_foot_refs = node.traverse(is_refnamed_footnote_ref) new_foot_refs = patch.traverse(is_refnamed_footnote_ref) refname_ids_map: Dict[str, List[str]] = {} - if len(old_foot_refs) != len(new_foot_refs): + if len(list(old_foot_refs)) != len(list(new_foot_refs)): old_foot_ref_rawsources = [ref.rawsource for ref in old_foot_refs] new_foot_ref_rawsources = [ref.rawsource for ref in new_foot_refs] logger.warning(__('inconsistent footnote references in translated message.' + @@ -388,7 +388,7 @@ class Locale(SphinxTransform): old_cite_refs: List[nodes.citation_reference] = node.traverse(is_citation_ref) new_cite_refs: List[nodes.citation_reference] = patch.traverse(is_citation_ref) refname_ids_map = {} - if len(old_cite_refs) != len(new_cite_refs): + if len(list(old_cite_refs)) != len(list(new_cite_refs)): old_cite_ref_rawsources = [ref.rawsource for ref in old_cite_refs] new_cite_ref_rawsources = [ref.rawsource for ref in new_cite_refs] logger.warning(__('inconsistent citation references in translated message.' + @@ -408,7 +408,7 @@ class Locale(SphinxTransform): old_xrefs = node.traverse(addnodes.pending_xref) new_xrefs = patch.traverse(addnodes.pending_xref) xref_reftarget_map = {} - if len(old_xrefs) != len(new_xrefs): + if len(list(old_xrefs)) != len(list(new_xrefs)): old_xref_rawsources = [xref.rawsource for xref in old_xrefs] new_xref_rawsources = [xref.rawsource for xref in new_xrefs] logger.warning(__('inconsistent term references in translated message.' + diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index a1b1defd7..25c82940c 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1011,7 +1011,7 @@ class LaTeXTranslator(SphinxTranslator): context = (r'\par' + CR + r'\vskip-\baselineskip' r'\vbox{\hbox{\strut}}\end{varwidth}%' + CR + context) self.needs_linetrimming = 1 - if len(node.traverse(nodes.paragraph)) >= 2: + if len(list(node.traverse(nodes.paragraph))) >= 2: self.table.has_oldproblematic = True if isinstance(node.parent.parent, nodes.thead) or (cell.col in self.table.stubs): if len(node) == 1 and isinstance(node[0], nodes.paragraph) and node.astext() == '': diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py index bd0ffa063..ba310e072 100644 --- a/sphinx/writers/text.py +++ b/sphinx/writers/text.py @@ -850,7 +850,7 @@ class TextTranslator(SphinxTranslator): self.end_state(first='%s. ' % self.list_counter[-1]) def visit_definition_list_item(self, node: Element) -> None: - self._classifier_count_in_li = len(node.traverse(nodes.classifier)) + self._classifier_count_in_li = len(list(node.traverse(nodes.classifier))) def depart_definition_list_item(self, node: Element) -> None: pass diff --git a/tests/test_util_nodes.py b/tests/test_util_nodes.py index cb2ae70a8..421930cf5 100644 --- a/tests/test_util_nodes.py +++ b/tests/test_util_nodes.py @@ -60,31 +60,31 @@ def test_NodeMatcher(): # search by node class matcher = NodeMatcher(nodes.paragraph) - assert len(doctree.traverse(matcher)) == 3 + assert len(list(doctree.traverse(matcher))) == 3 # search by multiple node classes matcher = NodeMatcher(nodes.paragraph, nodes.literal_block) - assert len(doctree.traverse(matcher)) == 4 + assert len(list(doctree.traverse(matcher))) == 4 # search by node attribute matcher = NodeMatcher(block=1) - assert len(doctree.traverse(matcher)) == 1 + assert len(list(doctree.traverse(matcher))) == 1 # search by node attribute (Any) matcher = NodeMatcher(block=Any) - assert len(doctree.traverse(matcher)) == 3 + assert len(list(doctree.traverse(matcher))) == 3 # search by both class and attribute matcher = NodeMatcher(nodes.paragraph, block=Any) - assert len(doctree.traverse(matcher)) == 2 + assert len(list(doctree.traverse(matcher))) == 2 # mismatched matcher = NodeMatcher(nodes.title) - assert len(doctree.traverse(matcher)) == 0 + assert len(list(doctree.traverse(matcher))) == 0 # search with Any does not match to Text node matcher = NodeMatcher(blah=Any) - assert len(doctree.traverse(matcher)) == 0 + assert len(list(doctree.traverse(matcher))) == 0 @pytest.mark.parametrize(