]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Docs: use Node.findall to avoid a deprecation warning (GH-99403)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 8 Apr 2023 08:24:27 +0000 (01:24 -0700)
committerGitHub <noreply@github.com>
Sat, 8 Apr 2023 08:24:27 +0000 (01:24 -0700)
(cherry picked from commit 1e9dfdacefa2c8c27762ba6491b0f570147ee355)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Doc/tools/extensions/c_annotations.py

index a845ef46c0ba940f0342654a7ed12798579c74cd..7cb6bd87103f6453e269077cb12bf810cb2dccfc 100644 (file)
@@ -20,6 +20,7 @@
 """
 
 from os import path
+import docutils
 from docutils import nodes
 from docutils.parsers.rst import directives
 from docutils.parsers.rst import Directive
@@ -41,6 +42,16 @@ REST_ROLE_MAP = {
 }
 
 
+# Monkeypatch nodes.Node.findall for forwards compatability
+# This patch can be dropped when the minimum Sphinx version is 4.4.0
+# or the minimum Docutils version is 0.18.1.
+if docutils.__version_info__ < (0, 18, 1):
+    def findall(self, *args, **kwargs):
+        return iter(self.traverse(*args, **kwargs))
+
+    nodes.Node.findall = findall
+
+
 class RCEntry:
     def __init__(self, name):
         self.name = name
@@ -87,7 +98,7 @@ class Annotations:
                 self.stable_abi_data[name] = record
 
     def add_annotations(self, app, doctree):
-        for node in doctree.traverse(addnodes.desc_content):
+        for node in doctree.findall(addnodes.desc_content):
             par = node.parent
             if par['domain'] != 'c':
                 continue