From 77bb3b30dc72a0b56559c0f4757949e4d1950561 Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Tue, 29 Jul 2025 14:15:10 +0100 Subject: [PATCH 1/3] [docutils] Add return types for a few docutils table methods --- .../docutils/docutils/parsers/rst/directives/tables.pyi | 9 +++++---- stubs/docutils/docutils/parsers/rst/states.pyi | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/stubs/docutils/docutils/parsers/rst/directives/tables.pyi b/stubs/docutils/docutils/parsers/rst/directives/tables.pyi index ebde406d577e..d7b68b98a740 100644 --- a/stubs/docutils/docutils/parsers/rst/directives/tables.pyi +++ b/stubs/docutils/docutils/parsers/rst/directives/tables.pyi @@ -3,6 +3,7 @@ from _typeshed import Incomplete from collections.abc import Callable from typing import ClassVar, Final +from docutils import nodes from docutils.parsers.rst import Directive __docformat__: Final = "reStructuredText" @@ -20,7 +21,7 @@ class Table(Directive): def extend_short_rows_with_empty_cells(self, columns, parts) -> None: ... class RSTTable(Table): - def run(self): ... + def run(self) -> list[nodes.table | nodes.system_message]: ... class CSVTable(Table): class DocutilsDialect(csv.Dialect): @@ -48,7 +49,7 @@ class CSVTable(Table): @staticmethod def check_requirements() -> None: ... def process_header_option(self): ... - def run(self): ... + def run(self) -> list[nodes.table | nodes.system_message]: ... def get_csv_data(self): ... @staticmethod def decode_from_csv(s): ... @@ -57,6 +58,6 @@ class CSVTable(Table): def parse_csv_data_into_rows(self, csv_data, dialect, source): ... class ListTable(Table): - def run(self): ... + def run(self) -> list[nodes.table | nodes.system_message]: ... def check_list_content(self, node): ... - def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns): ... + def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns) -> nodes.table: ... diff --git a/stubs/docutils/docutils/parsers/rst/states.pyi b/stubs/docutils/docutils/parsers/rst/states.pyi index 169b1699c7b4..c8e26855b6cc 100644 --- a/stubs/docutils/docutils/parsers/rst/states.pyi +++ b/stubs/docutils/docutils/parsers/rst/states.pyi @@ -219,7 +219,7 @@ class Body(RSTState): def isolate_grid_table(self): ... def isolate_simple_table(self): ... def malformed_table(self, block, detail: str = "", offset: int = 0): ... - def build_table(self, tabledata, tableline, stub_columns: int = 0, widths=None): ... + def build_table(self, tabledata, tableline, stub_columns: int = 0, widths=None) -> nodes.table: ... def build_table_row(self, rowdata, tableline): ... explicit: Incomplete def footnote(self, match): ... From fc085879d916774a9d214569e44578214c473c13 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Jul 2025 13:17:47 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/docutils/docutils/parsers/rst/directives/tables.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/docutils/docutils/parsers/rst/directives/tables.pyi b/stubs/docutils/docutils/parsers/rst/directives/tables.pyi index d7b68b98a740..1ab629a05fae 100644 --- a/stubs/docutils/docutils/parsers/rst/directives/tables.pyi +++ b/stubs/docutils/docutils/parsers/rst/directives/tables.pyi @@ -21,7 +21,7 @@ class Table(Directive): def extend_short_rows_with_empty_cells(self, columns, parts) -> None: ... class RSTTable(Table): - def run(self) -> list[nodes.table | nodes.system_message]: ... + def run(self) -> list[nodes.table | nodes.system_message]: ... class CSVTable(Table): class DocutilsDialect(csv.Dialect): From 86932bcc3c90938b984b57e60753743868edef14 Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Sun, 3 Aug 2025 13:29:24 +0100 Subject: [PATCH 3/3] Address review comment: Use Sequence rather than list --- stubs/docutils/docutils/parsers/rst/directives/tables.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/docutils/docutils/parsers/rst/directives/tables.pyi b/stubs/docutils/docutils/parsers/rst/directives/tables.pyi index 1ab629a05fae..cf0022f3f005 100644 --- a/stubs/docutils/docutils/parsers/rst/directives/tables.pyi +++ b/stubs/docutils/docutils/parsers/rst/directives/tables.pyi @@ -1,6 +1,6 @@ import csv from _typeshed import Incomplete -from collections.abc import Callable +from collections.abc import Callable, Sequence from typing import ClassVar, Final from docutils import nodes @@ -21,7 +21,7 @@ class Table(Directive): def extend_short_rows_with_empty_cells(self, columns, parts) -> None: ... class RSTTable(Table): - def run(self) -> list[nodes.table | nodes.system_message]: ... + def run(self) -> Sequence[nodes.table | nodes.system_message]: ... class CSVTable(Table): class DocutilsDialect(csv.Dialect): @@ -49,7 +49,7 @@ class CSVTable(Table): @staticmethod def check_requirements() -> None: ... def process_header_option(self): ... - def run(self) -> list[nodes.table | nodes.system_message]: ... + def run(self) -> Sequence[nodes.table | nodes.system_message]: ... def get_csv_data(self): ... @staticmethod def decode_from_csv(s): ... @@ -58,6 +58,6 @@ class CSVTable(Table): def parse_csv_data_into_rows(self, csv_data, dialect, source): ... class ListTable(Table): - def run(self) -> list[nodes.table | nodes.system_message]: ... + def run(self) -> Sequence[nodes.table | nodes.system_message]: ... def check_list_content(self, node): ... def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns) -> nodes.table: ...