3939HASH_LEN = 12
4040
4141
42- def _traverse_or_findall (node , condition , ** kwargs ):
43- """Triage node.traverse (docutils <0.18.1) vs node.findall.
44-
45- TODO: This check can be removed when the minimum supported docutils version
46- for numpydoc is docutils>=0.18.1
47- """
48- return (
49- node .findall (condition , ** kwargs )
50- if hasattr (node , "findall" )
51- else node .traverse (condition , ** kwargs )
52- )
53-
54-
5542def rename_references (app , what , name , obj , options , lines ):
5643 # decorate reference numbers so that there are no duplicates
5744 # these are later undecorated in the doctree, in relabel_references
@@ -92,12 +79,8 @@ def is_docstring_section(node):
9279 return False
9380
9481 sibling_sections = itertools .chain (
95- _traverse_or_findall (
96- section_node ,
97- is_docstring_section ,
98- include_self = True ,
99- descend = False ,
100- siblings = True ,
82+ section_node .findall (
83+ is_docstring_section , include_self = True , descend = False , siblings = True
10184 )
10285 )
10386 for sibling_section in sibling_sections :
@@ -116,7 +99,7 @@ def is_docstring_section(node):
11699
117100def relabel_references (app , doc ):
118101 # Change 'hash-ref' to 'ref' in label text
119- for citation_node in _traverse_or_findall ( doc , citation ):
102+ for citation_node in doc . findall ( citation ):
120103 if not _is_cite_in_numpydoc_docstring (citation_node ):
121104 continue
122105 label_node = citation_node [0 ]
@@ -136,22 +119,22 @@ def matching_pending_xref(node):
136119 and node [0 ].astext () == f"[{ ref_text } ]"
137120 )
138121
139- for xref_node in _traverse_or_findall ( ref .parent , matching_pending_xref ):
122+ for xref_node in ref .parent . findall ( matching_pending_xref ):
140123 xref_node .replace (xref_node [0 ], Text (f"[{ new_text } ]" ))
141124 ref .replace (ref_text , new_text .copy ())
142125
143126
144127def clean_backrefs (app , doc , docname ):
145128 # only::latex directive has resulted in citation backrefs without reference
146129 known_ref_ids = set ()
147- for ref in _traverse_or_findall ( doc , reference , descend = True ):
130+ for ref in doc . findall ( reference , descend = True ):
148131 for id_ in ref ["ids" ]:
149132 known_ref_ids .add (id_ )
150133 # some extensions produce backrefs to inline elements
151- for ref in _traverse_or_findall ( doc , inline , descend = True ):
134+ for ref in doc . findall ( inline , descend = True ):
152135 for id_ in ref ["ids" ]:
153136 known_ref_ids .add (id_ )
154- for citation_node in _traverse_or_findall ( doc , citation , descend = True ):
137+ for citation_node in doc . findall ( citation , descend = True ):
155138 # remove backrefs to non-existent refs
156139 citation_node ["backrefs" ] = [
157140 id_ for id_ in citation_node ["backrefs" ] if id_ in known_ref_ids
0 commit comments