Skip to content

Commit 6d44707

Browse files
committed
fix(mypy): Use slice assignment for docutils node children manipulation
Replace .clear() + .extend() with slice assignment (node[:] = children) to fix mypy errors about Sequence[Node] having no .clear() method and Node having no .extend() method. This is the idiomatic pattern used in Sphinx's codebase for modifying node children.
1 parent 67d2231 commit 6d44707

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

docs/_ext/argparse_exemplar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,7 @@ def process_node(
823823
else:
824824
new_children.append(child)
825825
if children_changed:
826-
node.children.clear()
827-
node.extend(new_children)
826+
node[:] = new_children # type: ignore[index]
828827

829828
return node
830829

@@ -1134,8 +1133,7 @@ def _extract_sections_from_container(
11341133
remaining_children.append(child)
11351134

11361135
# Update container with remaining children only
1137-
container.children.clear()
1138-
container.extend(remaining_children)
1136+
container[:] = remaining_children # type: ignore[index]
11391137

11401138
return container, extracted_sections
11411139

0 commit comments

Comments
 (0)