Skip to content

Commit 7654e1a

Browse files
authored
Better type handling to account for types-docutils bump (apache#53364)
1 parent 11b53f4 commit 7654e1a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

devel-common/src/sphinx_exts/substitution_extensions.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def condition(node):
6161
return isinstance(node, (nodes.literal_block, nodes.literal))
6262

6363
for node in self.document.traverse(condition):
64-
if _SUBSTITUTION_OPTION_NAME not in node:
64+
if not node.get(_SUBSTITUTION_OPTION_NAME):
6565
continue
6666

6767
# Some nodes don't have a direct document property, so walk up until we find it
@@ -76,11 +76,13 @@ def condition(node):
7676
old_child = child
7777
for name, value in substitution_defs.items():
7878
replacement = value.astext()
79-
child = nodes.Text(child.replace(f"|{name}|", replacement))
80-
node.replace(old_child, child)
79+
if isinstance(child, nodes.Text):
80+
child = nodes.Text(child.replace(f"|{name}|", replacement))
81+
if isinstance(node, nodes.Element):
82+
node.replace(old_child, child)
8183

8284
# The highlighter checks this -- without this, it will refuse to apply highlighting
83-
node.rawsource = node.astext()
85+
node.rawsource = node.astext() # type: ignore[attr-defined]
8486

8587

8688
def substitution_code_role(*args, **kwargs) -> tuple[list, list[Any]]:

0 commit comments

Comments
 (0)