Skip to content

Commit 1e9dfda

Browse files
authored
Docs: use Node.findall to avoid a deprecation warning (#99403)
1 parent a34c796 commit 1e9dfda

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Doc/tools/extensions/c_annotations.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"""
2121

2222
from os import path
23+
import docutils
2324
from docutils import nodes
2425
from docutils.parsers.rst import directives
2526
from docutils.parsers.rst import Directive
@@ -41,6 +42,16 @@
4142
}
4243

4344

45+
# Monkeypatch nodes.Node.findall for forwards compatability
46+
# This patch can be dropped when the minimum Sphinx version is 4.4.0
47+
# or the minimum Docutils version is 0.18.1.
48+
if docutils.__version_info__ < (0, 18, 1):
49+
def findall(self, *args, **kwargs):
50+
return iter(self.traverse(*args, **kwargs))
51+
52+
nodes.Node.findall = findall
53+
54+
4455
class RCEntry:
4556
def __init__(self, name):
4657
self.name = name
@@ -87,7 +98,7 @@ def __init__(self, refcount_filename, stable_abi_file):
8798
self.stable_abi_data[name] = record
8899

89100
def add_annotations(self, app, doctree):
90-
for node in doctree.traverse(addnodes.desc_content):
101+
for node in doctree.findall(addnodes.desc_content):
91102
par = node.parent
92103
if par['domain'] != 'c':
93104
continue

0 commit comments

Comments
 (0)