diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2022-01-03 00:57:31 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-03 00:57:31 +0900 |
commit | 08a87d945a8ca7770c589ea878e9b095ed35e6d4 (patch) | |
tree | 9ceec80c4117bef6e2f0a960c85d99237475cfe7 /sphinx/util/docutils.py | |
parent | a0919172190ee147d44288a0ac67712870ca965e (diff) | |
parent | 05a898ecb4ff8e654a053a1ba5131715a4514812 (diff) | |
download | sphinx-git-08a87d945a8ca7770c589ea878e9b095ed35e6d4.tar.gz |
Merge pull request #10044 from tk0miya/9777_Node.findall
Migrate to Node.findall() from Node.traverse()
Diffstat (limited to 'sphinx/util/docutils.py')
-rw-r--r-- | sphinx/util/docutils.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index 456fa9576..c3a6ff9e2 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -500,6 +500,16 @@ class SphinxTranslator(nodes.NodeVisitor): logger.warning(__('unknown node type: %r'), node, location=node) +# Node.findall() is a new interface to traverse a doctree since docutils-0.18. +# This applies a patch docutils-0.17 or older to be available Node.findall() +# method to use it from our codebase. +if __version_info__ < (0, 18): + def findall(self, *args, **kwargs): + return iter(self.traverse(*args, **kwargs)) + + Node.findall = findall # type: ignore + + # cache a vanilla instance of nodes.document # Used in new_document() function __document_cache__: Optional[nodes.document] = None |