From 825c729cb8cfc1e94e0dcb7cb5775e346686df7d Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sat, 29 Apr 2023 10:02:48 +0100 Subject: [PATCH 1/4] add 'paragraph' node to docutils --- stubs/docutils/docutils/nodes.pyi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stubs/docutils/docutils/nodes.pyi b/stubs/docutils/docutils/nodes.pyi index a187ba37252e..940ad893f67d 100644 --- a/stubs/docutils/docutils/nodes.pyi +++ b/stubs/docutils/docutils/nodes.pyi @@ -107,6 +107,9 @@ class Element(Node): def astext(self) -> str: ... def __getattr__(self, __name: str) -> Incomplete: ... +class TextElement(Element): + def __init__(self, rawsource: str = "", text: str = "", *children, **attributes): ... + class Text(Node, str): tagname: ClassVar[str] children: tuple[()] @@ -135,6 +138,8 @@ class document(Root, Structural, Element): def astext(self) -> str: ... def __getattr__(self, __name: str) -> Incomplete: ... +class paragraph(General, TextElement): ... + class NodeVisitor: def __init__(self, document: document): ... def __getattr__(self, __name: str) -> Incomplete: ... From 6ce97ebc7746900a4f82e600b7a7471a3abffa33 Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Sat, 29 Apr 2023 16:15:31 +0100 Subject: [PATCH 2/4] 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 940ad893f67d..75148e21ffff 100644 --- a/stubs/docutils/docutils/nodes.pyi +++ b/stubs/docutils/docutils/nodes.pyi @@ -108,7 +108,7 @@ class Element(Node): def __getattr__(self, __name: str) -> Incomplete: ... class TextElement(Element): - def __init__(self, rawsource: str = "", text: str = "", *children, **attributes): ... + def __init__(self, rawsource: str = "", text: str = "", *children: Node, **attributes) -> None: ... class Text(Node, str): tagname: ClassVar[str] From 8d051df2c76d9d15407967fdf4c795b8769c7748 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sat, 29 Apr 2023 17:04:01 +0100 Subject: [PATCH 3/4] Add missing things to Element stub --- stubs/docutils/docutils/nodes.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stubs/docutils/docutils/nodes.pyi b/stubs/docutils/docutils/nodes.pyi index 75148e21ffff..2866e551d8ba 100644 --- a/stubs/docutils/docutils/nodes.pyi +++ b/stubs/docutils/docutils/nodes.pyi @@ -1,9 +1,10 @@ +import sys import xml.dom.minidom from _typeshed import Incomplete from abc import abstractmethod from collections.abc import Callable, Generator, Iterable, Iterator, Sequence from typing import Any, ClassVar, Protocol, TypeVar, overload -from typing_extensions import Literal, Self +from typing_extensions import Literal, Self, SupportsIndex from docutils.transforms import Transformer @@ -79,6 +80,7 @@ class Node: class Element(Node): children: list[Node] + rawsource: str def __init__(self, rawsource: str = "", *children: Node, **attributes): ... def __len__(self) -> int: ... def __contains__(self, key: str | Node) -> bool: ... @@ -105,6 +107,9 @@ class Element(Node): def deepcopy(self) -> Self: ... def pformat(self, indent: str = " ", level: int = 0) -> str: ... def astext(self) -> str: ... + def index(self, item: Node, start: int = 0, stop: int = sys.maxsize) -> int: ... + def remove(self, item: Node) -> None: ... + def insert(self, index: SupportsIndex, item: Node | Element | None) -> None: ... def __getattr__(self, __name: str) -> Incomplete: ... class TextElement(Element): From a492aaf570cc40bff507e1af2dd3e5e9b023fa29 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sat, 29 Apr 2023 17:25:54 +0100 Subject: [PATCH 4/4] Fix insert() signature --- 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 2866e551d8ba..33f36fe20a6f 100644 --- a/stubs/docutils/docutils/nodes.pyi +++ b/stubs/docutils/docutils/nodes.pyi @@ -109,7 +109,7 @@ class Element(Node): def astext(self) -> str: ... def index(self, item: Node, start: int = 0, stop: int = sys.maxsize) -> int: ... def remove(self, item: Node) -> None: ... - def insert(self, index: SupportsIndex, item: Node | Element | None) -> None: ... + def insert(self, index: SupportsIndex, item: Node | Iterable[Node] | None) -> None: ... def __getattr__(self, __name: str) -> Incomplete: ... class TextElement(Element):