Skip to content

Commit 52989cf

Browse files
committed
[gen][nfc] Remove traverse method now upstream mistletoe.utils.traverse is fixed
Now my fixes <miyuchina/mistletoe#157> <miyuchina/mistletoe#158> <miyuchina/mistletoe#159> are in a released version, just use the upstream traverse implementation.
1 parent bfc12cc commit 52989cf

1 file changed

Lines changed: 2 additions & 28 deletions

File tree

build.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import threading
1818
import typing
1919
import urllib.parse
20-
from collections import namedtuple
2120
from contextlib import contextmanager
2221
from dataclasses import dataclass
2322
from http import HTTPStatus
@@ -266,31 +265,6 @@ def fm_get_opt(key: str, ty: type[T]) -> T | None:
266265
)
267266

268267

269-
TraverseResult = namedtuple("TraverseResult", ["node", "parent", "depth"])
270-
271-
272-
# Copied and fixed from mistletoe.utils.
273-
# TODO: Replace with call to lib version once a new release includes it.
274-
def traverse(
275-
source: mistletoe.token.Token,
276-
klass: type | None = None,
277-
depth: int | None = None,
278-
include_source: bool = False,
279-
) -> Iterator[TraverseResult]:
280-
current_depth = 0
281-
if include_source:
282-
yield TraverseResult(source, None, current_depth)
283-
next_children = [(source, c) for c in getattr(source, "children", [])]
284-
while next_children and (depth is None or current_depth > depth):
285-
current_depth += 1
286-
new_children = []
287-
for parent, child in next_children:
288-
if klass is None or isinstance(child, klass):
289-
yield TraverseResult(child, parent, current_depth)
290-
new_children.extend([(child, c) for c in getattr(child, "children", [])])
291-
next_children = new_children
292-
293-
294268
def strip_anchor(target: str) -> str:
295269
return target.split("#")[0]
296270

@@ -371,7 +345,7 @@ def extract_and_remove_article_title(doc: mistletoe.Document) -> str:
371345

372346
def check_and_rewrite_links(doc: mistletoe.Document) -> None:
373347
# Rewrite any /pages/foo.md links to appropriate permalinks.
374-
for t in traverse(doc, klass=mistletoe.span_token.Link):
348+
for t in mistletoe.utils.traverse(doc, klass=mistletoe.span_token.Link):
375349
# TODO: check anchor links, including within the current document.
376350
stripped_target = strip_anchor(t.node.target)
377351
check_link_target(stripped_target, src_file)
@@ -387,7 +361,7 @@ def process_changelog(
387361
changelog_heading = None
388362
last_major_update = None
389363
last_minor_update = None
390-
for t in traverse(doc, klass=mistletoe.block_token.Heading):
364+
for t in mistletoe.utils.traverse(doc, klass=mistletoe.block_token.Heading):
391365
if changelog_heading:
392366
err("changelog wasn't last heading")
393367
# TODO: error if changelog heading isn't the last

0 commit comments

Comments
 (0)