39
39
HASH_LEN = 12
40
40
41
41
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
-
55
42
def rename_references (app , what , name , obj , options , lines ):
56
43
# decorate reference numbers so that there are no duplicates
57
44
# these are later undecorated in the doctree, in relabel_references
@@ -92,12 +79,8 @@ def is_docstring_section(node):
92
79
return False
93
80
94
81
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
101
84
)
102
85
)
103
86
for sibling_section in sibling_sections :
@@ -116,7 +99,7 @@ def is_docstring_section(node):
116
99
117
100
def relabel_references (app , doc ):
118
101
# 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 ):
120
103
if not _is_cite_in_numpydoc_docstring (citation_node ):
121
104
continue
122
105
label_node = citation_node [0 ]
@@ -136,22 +119,22 @@ def matching_pending_xref(node):
136
119
and node [0 ].astext () == f"[{ ref_text } ]"
137
120
)
138
121
139
- for xref_node in _traverse_or_findall ( ref .parent , matching_pending_xref ):
122
+ for xref_node in ref .parent . findall ( matching_pending_xref ):
140
123
xref_node .replace (xref_node [0 ], Text (f"[{ new_text } ]" ))
141
124
ref .replace (ref_text , new_text .copy ())
142
125
143
126
144
127
def clean_backrefs (app , doc , docname ):
145
128
# only::latex directive has resulted in citation backrefs without reference
146
129
known_ref_ids = set ()
147
- for ref in _traverse_or_findall ( doc , reference , descend = True ):
130
+ for ref in doc . findall ( reference , descend = True ):
148
131
for id_ in ref ["ids" ]:
149
132
known_ref_ids .add (id_ )
150
133
# 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 ):
152
135
for id_ in ref ["ids" ]:
153
136
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 ):
155
138
# remove backrefs to non-existent refs
156
139
citation_node ["backrefs" ] = [
157
140
id_ for id_ in citation_node ["backrefs" ] if id_ in known_ref_ids
0 commit comments