From 67176a41e68d72167f7e48720f3e11f17fe04db0 Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Fri, 8 Mar 2024 02:06:42 +0000 Subject: [PATCH] improve type annotations in 'docutils.parsers.rst.tableparser' (#11530) Co-authored-by: daniel.eades --- .../docutils/parsers/rst/tableparser.pyi | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 stubs/docutils/docutils/parsers/rst/tableparser.pyi diff --git a/stubs/docutils/docutils/parsers/rst/tableparser.pyi b/stubs/docutils/docutils/parsers/rst/tableparser.pyi new file mode 100644 index 000000000..76b06eb90 --- /dev/null +++ b/stubs/docutils/docutils/parsers/rst/tableparser.pyi @@ -0,0 +1,64 @@ +from re import Pattern +from typing import ClassVar +from typing_extensions import TypeAlias + +from docutils import DataError +from docutils.statemachine import Stringlist + +_Cell: TypeAlias = tuple[int, int, int, list[str]] +_Row: TypeAlias = list[_Cell | None] +_Colspecs: TypeAlias = list[int] + +__docformat__: str + +class TableMarkupError(DataError): + offset: int + def __init__(self, *args, **kwargs) -> None: ... + +class TableParser: + head_body_separator_pat: ClassVar[Pattern[str] | None] + double_width_pad_char: ClassVar[str] + def parse(self, block: Stringlist) -> tuple[_Colspecs, list[_Row], list[_Row]]: ... + def find_head_body_sep(self) -> None: ... + +class GridTableParser(TableParser): + head_body_separator_pat: ClassVar[Pattern[str]] + block: Stringlist + bottom: int + right: int + head_body_sep: int + done: list[int] + cells: list[_Cell] + rowseps: dict[int, list[int]] + colseps: dict[int, list[int]] + def setup(self, block: Stringlist) -> None: ... + def parse_table(self) -> None: ... + def mark_done(self, top: int, left: int, bottom: int, right: int) -> None: ... + def check_parse_complete(self) -> bool: ... + def scan_cell(self, top: int, left: int) -> tuple[int, int, dict[int, list[int]], dict[int, list[int]]]: ... + def scan_right(self, top: int, left: int) -> tuple[int, int, dict[int, list[int]], dict[int, list[int]]]: ... + def scan_down(self, top: int, left: int, right: int) -> tuple[int, dict[int, list[int]], dict[int, list[int]]]: ... + def scan_left(self, top: int, left: int, bottom: int, right: int) -> tuple[dict[int, list[int]], dict[int, list[int]]]: ... + def scan_up(self, top: int, left: int, bottom: int, right: int) -> dict[int, list[int]]: ... + def structure_from_cells(self) -> tuple[_Colspecs, list[_Row], list[_Row]]: ... + +class SimpleTableParser(TableParser): + head_body_separator_pat: ClassVar[Pattern[str]] + span_pat: ClassVar[Pattern[str]] + block: Stringlist + head_body_sep: int + columns: list[tuple[int, int]] + border_end: int + table: tuple[list[int], list[_Row], list[_Row]] + done: list[int] + rowseps: dict[int, tuple[int]] + colseps: dict[int, tuple[int]] + def setup(self, block: Stringlist) -> None: ... + def parse_table(self) -> None: ... + def parse_columns(self, line: str, offset: int) -> list[tuple[int, int]]: ... + def init_row(self, colspec: list[tuple[int, int]], offset: int) -> list[_Cell]: ... + def parse_row(self, lines: list[str], start: int, spanline: tuple[str, int] | None = ...) -> None: ... + def check_columns(self, lines: list[str], first_line: int, columns: list[tuple[int, int]]) -> None: ... + def structure_from_cells(self) -> tuple[_Colspecs, list[_Row], list[_Row]]: ... + +def update_dict_of_lists(master: dict[int, list[int]], newdata: dict[int, list[int]]) -> None: ...