Skip to content

Commit 9422588

Browse files
authored
PEP 676: Use docutils.nodes.Node.findall (#2363)
1 parent 99bb6aa commit 9422588

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

generate_rss.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import email.utils
77
from pathlib import Path
88

9+
import docutils
910
from docutils import frontend
1011
from docutils import nodes
1112
from docutils import utils
@@ -19,6 +20,14 @@ def _format_rfc_2822(dt: datetime.datetime) -> str:
1920
return email.utils.format_datetime(dt, usegmt=True)
2021

2122

23+
# Monkeypatch nodes.Node.findall for forwards compatability
24+
if docutils.__version_info__ < (0, 18):
25+
def findall(self, *args, **kwargs):
26+
return iter(self.traverse(*args, **kwargs))
27+
28+
nodes.Node.findall = findall
29+
30+
2231
entry.formatRFC2822 = feed.formatRFC2822 = _format_rfc_2822
2332
line_cache: dict[Path, dict[str, str]] = {}
2433

@@ -62,8 +71,7 @@ def parse_rst(text: str) -> nodes.document:
6271
def pep_abstract(full_path: Path) -> str:
6372
"""Return the first paragraph of the PEP abstract"""
6473
text = full_path.read_text(encoding="utf-8")
65-
# TODO replace .traverse with .findall when Sphinx updates to docutils>=0.18.1
66-
for node in parse_rst(text).traverse(nodes.section):
74+
for node in parse_rst(text).findall(nodes.section):
6775
if node.next_node(nodes.title).astext() == "Abstract":
6876
return node.next_node(nodes.paragraph).astext().strip().replace("\n", " ")
6977
return ""

pep_sphinx_extensions/pep_processor/html/pep_html_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_doc_context(self, docname: str, body: str, _metatags: str) -> dict:
3838
toc_tree = self.env.tocs[docname].deepcopy()
3939
if len(toc_tree[0]) > 1:
4040
toc_tree = toc_tree[0][1] # don't include document title
41-
for node in toc_tree.traverse(nodes.reference):
41+
for node in toc_tree.findall(nodes.reference):
4242
node["refuri"] = node["anchorname"] or '#' # fix targets
4343
toc = self.render_partial(toc_tree)["fragment"]
4444
else:

0 commit comments

Comments
 (0)