Skip to content

Commit 9772c42

Browse files
docutils: add nodes.General; make Element iterable (#10099)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 4097522 commit 9772c42

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

stubs/docutils/@tests/stubtest_allowlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ docutils.nodes.Element.__getattr__
1010
docutils.nodes.NodeVisitor.__getattr__
1111
docutils.nodes.document.__getattr__
1212
docutils.nodes.document.__init__
13+
docutils.nodes.Element.__iter__ # doesn't exist at runtime, but the class is iterable due to __getitem__
1314
docutils.parsers.rst.Directive.__getattr__
1415
docutils.transforms.Transform.__getattr__
1516
docutils.transforms.Transformer.__getattr__

stubs/docutils/docutils/nodes.pyi

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import xml.dom.minidom
22
from _typeshed import Incomplete
33
from abc import abstractmethod
4-
from collections.abc import Callable, Generator, Iterable, Sequence
4+
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
55
from typing import Any, ClassVar, Protocol, TypeVar, overload
66
from typing_extensions import Literal, Self
77

@@ -82,6 +82,9 @@ class Element(Node):
8282
def __init__(self, rawsource: str = "", *children: Node, **attributes): ...
8383
def __len__(self) -> int: ...
8484
def __contains__(self, key: str | Node) -> bool: ...
85+
# '__iter__' is added as workaround, since mypy doesn't support classes that are iterable via '__getitem__'
86+
# see https://github.com/python/typeshed/pull/10099#issuecomment-1528789395
87+
def __iter__(self) -> Iterator[Node]: ...
8588
@overload
8689
def __getitem__(self, key: str) -> Any: ...
8790
@overload
@@ -120,6 +123,8 @@ class Text(Node, str):
120123
def lstrip(self, chars: str | None = None) -> str: ...
121124

122125
class Structural: ...
126+
class Body: ...
127+
class General(Body): ...
123128
class Root: ...
124129

125130
class document(Root, Structural, Element):

0 commit comments

Comments
 (0)