From 2681a916aeaa82e9d1861b17a161a3602ee9596e Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sat, 29 Apr 2023 07:09:18 +0100 Subject: [PATCH 1/6] add docutils.nodes.General stub --- stubs/docutils/docutils/nodes.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/docutils/docutils/nodes.pyi b/stubs/docutils/docutils/nodes.pyi index 30c32ed0ce6e..7fc1903437ce 100644 --- a/stubs/docutils/docutils/nodes.pyi +++ b/stubs/docutils/docutils/nodes.pyi @@ -120,6 +120,8 @@ class Text(Node, str): def lstrip(self, chars: str | None = None) -> str: ... class Structural: ... +class Body: ... +class General(Body): ... class Root: ... class document(Root, Structural, Element): From 359783bf216011ca2dfb95b6555c596a6396a804 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sat, 29 Apr 2023 15:19:57 +0100 Subject: [PATCH 2/6] lie to mypy --- stubs/docutils/docutils/nodes.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stubs/docutils/docutils/nodes.pyi b/stubs/docutils/docutils/nodes.pyi index 7fc1903437ce..aef72d64a4d9 100644 --- a/stubs/docutils/docutils/nodes.pyi +++ b/stubs/docutils/docutils/nodes.pyi @@ -1,7 +1,7 @@ import xml.dom.minidom from _typeshed import Incomplete from abc import abstractmethod -from collections.abc import Callable, Generator, Iterable, Sequence +from collections.abc import Callable, Generator, Iterable, Iterator, Sequence from typing import Any, ClassVar, Protocol, TypeVar, overload from typing_extensions import Literal, Self @@ -82,6 +82,9 @@ class Element(Node): def __init__(self, rawsource: str = "", *children: Node, **attributes): ... def __len__(self) -> int: ... def __contains__(self, key: str | Node) -> bool: ... + # '__iter__' is added as workaround, since mypy doesn't support iterators defined using '__get_item__' + # see https://github.com/python/typeshed/pull/10099#issuecomment-1528789395 + def __iter__(self) -> Iterator[Node]: ... @overload def __getitem__(self, key: str) -> Any: ... @overload From 892a539e718e41ada730a1bd2393983eafc43ad3 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sat, 29 Apr 2023 15:23:54 +0100 Subject: [PATCH 3/6] fixup --- tests/stubtest_allowlists/py3_common.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 5a41f9b9e265..b77409207ffc 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -606,6 +606,7 @@ wsgiref.handlers.BaseHandler.status # Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__) # These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220 ctypes.Array.__iter__ +docutils.nodes.Element.__iter__ mmap.mmap.__iter__ mmap.mmap.__contains__ xml.etree.ElementTree.Element.__iter__ From 3b4e23b631904df783165de11722d22e2d9c4718 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sat, 29 Apr 2023 15:29:08 +0100 Subject: [PATCH 4/6] fixup --- stubs/docutils/@tests/stubtest_allowlist.txt | 1 + tests/stubtest_allowlists/py3_common.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/docutils/@tests/stubtest_allowlist.txt b/stubs/docutils/@tests/stubtest_allowlist.txt index e8229378f968..db7dedf6a542 100644 --- a/stubs/docutils/@tests/stubtest_allowlist.txt +++ b/stubs/docutils/@tests/stubtest_allowlist.txt @@ -10,6 +10,7 @@ docutils.nodes.Element.__getattr__ docutils.nodes.NodeVisitor.__getattr__ docutils.nodes.document.__getattr__ docutils.nodes.document.__init__ +docutils.nodes.Element.__iter__ docutils.parsers.rst.Directive.__getattr__ docutils.transforms.Transform.__getattr__ docutils.transforms.Transformer.__getattr__ diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index b77409207ffc..5a41f9b9e265 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -606,7 +606,6 @@ wsgiref.handlers.BaseHandler.status # Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__) # These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220 ctypes.Array.__iter__ -docutils.nodes.Element.__iter__ mmap.mmap.__iter__ mmap.mmap.__contains__ xml.etree.ElementTree.Element.__iter__ From 1ccefb2bb7a3f01938d3eca8584c6ca382fb8cd0 Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Sat, 29 Apr 2023 15:32:20 +0100 Subject: [PATCH 5/6] Update stubs/docutils/@tests/stubtest_allowlist.txt Co-authored-by: Alex Waygood --- stubs/docutils/@tests/stubtest_allowlist.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/docutils/@tests/stubtest_allowlist.txt b/stubs/docutils/@tests/stubtest_allowlist.txt index db7dedf6a542..82dcbd5eb6e0 100644 --- a/stubs/docutils/@tests/stubtest_allowlist.txt +++ b/stubs/docutils/@tests/stubtest_allowlist.txt @@ -10,7 +10,7 @@ docutils.nodes.Element.__getattr__ docutils.nodes.NodeVisitor.__getattr__ docutils.nodes.document.__getattr__ docutils.nodes.document.__init__ -docutils.nodes.Element.__iter__ +docutils.nodes.Element.__iter__ # doesn't exist at runtime, but the class is iterable due to __getitem__ docutils.parsers.rst.Directive.__getattr__ docutils.transforms.Transform.__getattr__ docutils.transforms.Transformer.__getattr__ From 9066ae1261a1420e7aca252e6b21e0be7711ce61 Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Sat, 29 Apr 2023 15:32:33 +0100 Subject: [PATCH 6/6] Update stubs/docutils/docutils/nodes.pyi Co-authored-by: Alex Waygood --- stubs/docutils/docutils/nodes.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/docutils/docutils/nodes.pyi b/stubs/docutils/docutils/nodes.pyi index aef72d64a4d9..a187ba37252e 100644 --- a/stubs/docutils/docutils/nodes.pyi +++ b/stubs/docutils/docutils/nodes.pyi @@ -82,7 +82,7 @@ class Element(Node): def __init__(self, rawsource: str = "", *children: Node, **attributes): ... def __len__(self) -> int: ... def __contains__(self, key: str | Node) -> bool: ... - # '__iter__' is added as workaround, since mypy doesn't support iterators defined using '__get_item__' + # '__iter__' is added as workaround, since mypy doesn't support classes that are iterable via '__getitem__' # see https://github.com/python/typeshed/pull/10099#issuecomment-1528789395 def __iter__(self) -> Iterator[Node]: ... @overload