[Python-checkins] Docs: use Node.findall to avoid a deprecation warning (#99403)

hugovk webhook-mailer at python.org
Sat Apr 8 03:56:28 EDT 2023


https://github.com/python/cpython/commit/1e9dfdacefa2c8c27762ba6491b0f570147ee355
commit: 1e9dfdacefa2c8c27762ba6491b0f570147ee355
branch: main
author: Adam Turner <9087854+AA-Turner at users.noreply.github.com>
committer: hugovk <hugovk at users.noreply.github.com>
date: 2023-04-08T10:56:20+03:00
summary:

Docs: use Node.findall to avoid a deprecation warning (#99403)

files:
M Doc/tools/extensions/c_annotations.py

diff --git a/Doc/tools/extensions/c_annotations.py b/Doc/tools/extensions/c_annotations.py
index 5af56433f415..3551bfa4c0f1 100644
--- a/Doc/tools/extensions/c_annotations.py
+++ b/Doc/tools/extensions/c_annotations.py
@@ -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 @@
 }
 
 
+# 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 @@ def __init__(self, refcount_filename, stable_abi_file):
                 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



More information about the Python-checkins mailing list