From 66130790d60d4c08022e2b45cd71a7bac5c6ff2a Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 26 Feb 2024 19:37:43 +0000 Subject: [PATCH 01/26] improve type annotations in 'docutils.statemachine' --- stubs/docutils/docutils/statemachine.pyi | 202 ++++++++++++++++++++++- 1 file changed, 200 insertions(+), 2 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 0f6820f054ea..7f1396c869ec 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,3 +1,201 @@ -from _typeshed import Incomplete +from collections.abc import Callable, Generator, Iterator, Sequence +from re import Match, Pattern +from typing import Any, Generic, TypeAlias, TypeVar, overload +from typing_extensions import Self -def __getattr__(name: str) -> Incomplete: ... +__docformat__: str + +_Context = TypeVar("_Context") +_TransitionResult: TypeAlias = tuple[_Context, str | None, list[str]] +_TransitionMethod: TypeAlias = Callable[[Match[str], _Context, str], _TransitionResult[_Context]] + +class StateMachine(Generic[_Context]): + input_lines: StringList | None + input_offset: int + line: str | None + line_offset: int + debug: bool + initial_state: str + current_state: list[State[_Context]] + states: dict[str, State[_Context]] + observers: list[Callable[[Self], None]] + def __init__(self, state_classes: Sequence[type[State[_Context]]], initial_state: str, debug: bool = False) -> None: ... + def unlink(self) -> None: ... + def run( + self, + input_lines: list[str] | StringList, + input_offset: int = 0, + context: Any | None = None, + input_source: str | None = None, + initial_state: str | None = None, + ) -> list[Any]: ... + def get_state(self, next_state: str | None = None) -> State[_Context]: ... + def next_line(self, n: int = 1) -> str: ... + def is_next_line_blank(self) -> bool: ... + def at_eof(self) -> bool: ... + def at_bof(self) -> bool: ... + def previous_line(self, n: int = 1) -> str: ... + def goto_line(self, line_offset: int) -> None: ... + def get_source(self, line_offset: int) -> str: ... + def abs_line_offset(self) -> int: ... + def abs_line_number(self) -> int: ... + def get_source_and_line(self, lineno: int | None = None) -> tuple[str, int]: ... + def insert_input(self, input_lines: list[str] | StringList, source: str) -> None: ... + def get_text_block(self, flush_left: bool = False) -> StringList: ... + def check_line( + self, context: _Context, state: State[_Context], transitions: list[str] | None = ... + ) -> _TransitionResult[_Context]: ... + def add_state(self, state_class: type[State[_Context]]) -> None: ... + def add_states(self, state_classes: Sequence[type[State[_Context]]]) -> None: ... + def runtime_init(self) -> None: ... + def error(self) -> None: ... + def attach_observer(self, observer) -> None: ... + def detach_observer(self, observer) -> None: ... + def notify_observers(self) -> None: ... + +class State(Generic[_Context]): + patterns: dict[str, str | Pattern[str]] | None + initial_transitions: Sequence[str] | Sequence[tuple[str, str]] | None + nested_sm: type[StateMachine[_Context]] | None + nested_sm_kwargs: dict[str, Any] | None + transition_order: list[str] + transitions: dict[str, tuple[Pattern[str], Callable[[], None], str]] + state_machine: StateMachine[_Context] + debug: bool + def __init__(self, state_machine: StateMachine[_Context], debug: bool = False) -> None: ... + def runtime_init(self) -> None: ... + def unlink(self) -> None: ... + def add_initial_transitions(self) -> None: ... + def add_transitions(self, names: list[str], transitions) -> None: ... + def add_transition(self, name: str, transition: tuple[Pattern[str], str, str]) -> None: ... + def remove_transition(self, name: str) -> None: ... + def make_transition( + self, name: str, next_state: str | None = None + ) -> tuple[Pattern[str], _TransitionMethod[_Context], str]: ... + def make_transitions( + self, name_list: list[str | tuple[str] | tuple[str, str]] + ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]]: ... + def no_match( + self, context: Any, transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]] + ) -> _TransitionResult[_Context]: ... + def bof(self, context: _Context) -> tuple[_Context, list[str]]: ... + def eof(self, context: _Context) -> list[str]: ... + def nop(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + +class StateMachineWS(StateMachine[_Context]): + def get_indented(self, until_blank: bool = False, strip_indent: bool = True) -> tuple[StringList, int, int, bool]: ... + def get_known_indented( + self, indent: int, until_blank: bool = False, strip_indent: bool = True + ) -> tuple[list[str], int, bool]: ... + def get_first_known_indented( + self, indent: int, until_blank: bool = False, strip_indent: bool = True, strip_top: bool = True + ) -> tuple[list[str], int, int, bool]: ... + +class StateWS(State[_Context]): + indent_sm: type[StateMachine[_Context]] | None + indent_sm_kwargs: dict[str, Any] | None + known_indent_sm: type[StateMachine[_Context]] | None + known_indent_sm_kwargs: dict[str, Any] | None + ws_patterns: dict[str, str] + ws_initial_transitions: Sequence[str] + def __init__(self, state_machine: StateMachine[_Context], debug: bool = False) -> None: ... + def add_initial_transitions(self) -> None: ... + def blank(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def first_known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + +class _SearchOverride: + def match(self, pattern: Pattern[str]) -> Match[str]: ... + +class SearchStateMachine(_SearchOverride, StateMachine[_Context]): ... +class SearchStateMachineWS(_SearchOverride, StateMachineWS[_Context]): ... + +_Data = TypeVar("_Data") + +class ViewList(Generic[_Data]): + data: list[_Data] + items: list[tuple[str, int]] + parent: ViewList[_Data] + parent_offset: int + def __init__( + self, + initlist: ViewList[_Data] | list[_Data] | None = None, + source: str | None = None, + items: list[tuple[str, int]] | None = None, + parent: ViewList[_Data] | None = None, + parent_offset: int | None = None, + ) -> None: ... + def __lt__(self, other: Any) -> bool: ... + def __le__(self, other: Any) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __gt__(self, other: Any) -> bool: ... + def __ge__(self, other: Any) -> bool: ... + def __contains__(self, item: ViewList[_Data]) -> bool: ... + def __len__(self) -> int: ... + @overload + def __getitem__(self, i: slice) -> ViewList[_Data]: ... + @overload + def __getitem__(self, i: int) -> _Data: ... + @overload + def __setitem__(self, i: slice, item: ViewList[_Data]) -> None: ... + @overload + def __setitem__(self, i: int, item: _Data) -> None: ... + def __delitem__(self, i: int) -> None: ... + def __add__(self, other: ViewList[_Data]) -> None: ... + def __radd__(self, other: ViewList[_Data]) -> None: ... + def __iadd__(self, other: Self) -> Self: ... + def __mul__(self, n: int) -> ViewList[_Data]: ... + __rmul__: Any = ... + def __imul__(self, n: int) -> Self: ... + def extend(self, other: ViewList[_Data]) -> None: ... + def append(self, item: _Data, source: str | None = None, offset: int = 0) -> None: ... + def insert(self, i: int, item: _Data, source: str | None = None, offset: int = 0) -> None: ... + def pop(self, i: int = -1) -> _Data: ... + def trim_start(self, n: int = 1) -> None: ... + def trim_end(self, n: int = 1) -> None: ... + def remove(self, item: _Data) -> None: ... + def count(self, item: _Data) -> int: ... + def index(self, item: _Data) -> int: ... + def reverse(self) -> None: ... + def sort(self, *args: tuple[_Data, tuple[str, int]]) -> None: ... + def info(self, i: int) -> tuple[str, int]: ... + def source(self, i: int) -> str: ... + def offset(self, i: int) -> int: ... + def disconnect(self) -> None: ... + def xitems(self) -> Generator[tuple[str, int, str], None, None]: ... + def pprint(self) -> None: ... + + # dummy atribute to indicate to mypy that ViewList is Iterable[str] + def __iter__(self) -> Iterator[str]: ... + +class StringList(ViewList[str]): + def trim_left(self, length: int, start: int = 0, end: int = ...) -> None: ... + def get_text_block(self, start: int, flush_left: bool = False) -> StringList: ... + def get_indented( + self, + start: int = 0, + until_blank: bool = False, + strip_indent: bool = True, + block_indent: int | None = None, + first_indent: int | None = None, + ) -> tuple[StringList, int, bool]: ... + def get_2D_block(self, top: int, left: int, bottom: int, right: int, strip_indent: bool = True) -> StringList: ... + def pad_double_width(self, pad_char: str) -> None: ... + def replace(self, old: str, new: str) -> None: ... + +class StateMachineError(Exception): ... +class UnknownStateError(StateMachineError): ... +class DuplicateStateError(StateMachineError): ... +class UnknownTransitionError(StateMachineError): ... +class DuplicateTransitionError(StateMachineError): ... +class TransitionPatternNotFound(StateMachineError): ... +class TransitionMethodNotFound(StateMachineError): ... +class UnexpectedIndentationError(StateMachineError): ... +class TransitionCorrection(Exception): ... +class StateCorrection(Exception): ... + +def string2lines( + astring: str, tab_width: int = 8, convert_whitespace: bool = False, whitespace: Pattern[str] = ... +) -> list[str]: ... From e41f990a3a85015f5741c47b505d6fbc454c4620 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Tue, 27 Feb 2024 07:18:07 +0000 Subject: [PATCH 02/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 7f1396c869ec..51ce0f26298c 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable, Generator, Iterator, Sequence from re import Match, Pattern -from typing import Any, Generic, TypeAlias, TypeVar, overload -from typing_extensions import Self +from typing import Any, Generic, TypeVar, overload +from typing_extensions import Self, TypeAlias __docformat__: str From 41986daa3df4c28edefaeb0b18ebb114af6d347d Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Tue, 27 Feb 2024 07:24:23 +0000 Subject: [PATCH 03/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 34 +++++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 51ce0f26298c..58e83b420feb 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,13 +1,11 @@ from collections.abc import Callable, Generator, Iterator, Sequence from re import Match, Pattern from typing import Any, Generic, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Self __docformat__: str _Context = TypeVar("_Context") -_TransitionResult: TypeAlias = tuple[_Context, str | None, list[str]] -_TransitionMethod: TypeAlias = Callable[[Match[str], _Context, str], _TransitionResult[_Context]] class StateMachine(Generic[_Context]): input_lines: StringList | None @@ -44,7 +42,7 @@ class StateMachine(Generic[_Context]): def get_text_block(self, flush_left: bool = False) -> StringList: ... def check_line( self, context: _Context, state: State[_Context], transitions: list[str] | None = ... - ) -> _TransitionResult[_Context]: ... + ) -> tuple[_Context, str | None, list[str]]: ... def add_state(self, state_class: type[State[_Context]]) -> None: ... def add_states(self, state_classes: Sequence[type[State[_Context]]]) -> None: ... def runtime_init(self) -> None: ... @@ -71,16 +69,24 @@ class State(Generic[_Context]): def remove_transition(self, name: str) -> None: ... def make_transition( self, name: str, next_state: str | None = None - ) -> tuple[Pattern[str], _TransitionMethod[_Context], str]: ... + ) -> tuple[Pattern[str], Callable[[Match[str], _Context, str], tuple[_Context, str | None, list[str]]], str]: ... def make_transitions( self, name_list: list[str | tuple[str] | tuple[str, str]] - ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]]: ... + ) -> tuple[ + list[str], + dict[str, tuple[Pattern[str], Callable[[Match[str], _Context, str], tuple[_Context, str | None, list[str]]], str]], + ]: ... def no_match( - self, context: Any, transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]] - ) -> _TransitionResult[_Context]: ... + self, + context: Any, + transitions: tuple[ + list[str], + dict[str, tuple[Pattern[str], Callable[[Match[str], _Context, str], tuple[_Context, str | None, list[str]]], str]], + ], + ) -> tuple[_Context, str | None, list[str]]: ... def bof(self, context: _Context) -> tuple[_Context, list[str]]: ... def eof(self, context: _Context) -> list[str]: ... - def nop(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def nop(self, match: Match[str], context: _Context, next_state: str) -> tuple[_Context, str | None, list[str]]: ... class StateMachineWS(StateMachine[_Context]): def get_indented(self, until_blank: bool = False, strip_indent: bool = True) -> tuple[StringList, int, int, bool]: ... @@ -100,10 +106,12 @@ class StateWS(State[_Context]): ws_initial_transitions: Sequence[str] def __init__(self, state_machine: StateMachine[_Context], debug: bool = False) -> None: ... def add_initial_transitions(self) -> None: ... - def blank(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... - def indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... - def known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... - def first_known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def blank(self, match: Match[str], context: _Context, next_state: str) -> tuple[_Context, str | None, list[str]]: ... + def indent(self, match: Match[str], context: _Context, next_state: str) -> tuple[_Context, str | None, list[str]]: ... + def known_indent(self, match: Match[str], context: _Context, next_state: str) -> tuple[_Context, str | None, list[str]]: ... + def first_known_indent( + self, match: Match[str], context: _Context, next_state: str + ) -> tuple[_Context, str | None, list[str]]: ... class _SearchOverride: def match(self, pattern: Pattern[str]) -> Match[str]: ... From 079d055fd40e928686a615a62b28296afe289f05 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Tue, 27 Feb 2024 07:35:01 +0000 Subject: [PATCH 04/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 2 -- 1 file changed, 2 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 58e83b420feb..0ab263fd835a 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -3,8 +3,6 @@ from re import Match, Pattern from typing import Any, Generic, TypeVar, overload from typing_extensions import Self -__docformat__: str - _Context = TypeVar("_Context") class StateMachine(Generic[_Context]): From 61f182a9ebe1366cd555c7beb7fecc6e2274710a Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sat, 2 Mar 2024 08:01:59 +0000 Subject: [PATCH 05/26] use type aliases --- stubs/docutils/docutils/statemachine.pyi | 34 +++++++++--------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 0ab263fd835a..cc9a4c50a523 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,9 +1,11 @@ from collections.abc import Callable, Generator, Iterator, Sequence from re import Match, Pattern -from typing import Any, Generic, TypeVar, overload +from typing import Any, Generic, TypeAlias, TypeVar, overload from typing_extensions import Self _Context = TypeVar("_Context") +_TransitionResult: TypeAlias = tuple[_Context, str | None, list[str]] +_TransitionMethod: TypeAlias = Callable[[Match[str], _Context, str], _TransitionResult[_Context]] class StateMachine(Generic[_Context]): input_lines: StringList | None @@ -40,7 +42,7 @@ class StateMachine(Generic[_Context]): def get_text_block(self, flush_left: bool = False) -> StringList: ... def check_line( self, context: _Context, state: State[_Context], transitions: list[str] | None = ... - ) -> tuple[_Context, str | None, list[str]]: ... + ) -> _TransitionResult[_Context]: ... def add_state(self, state_class: type[State[_Context]]) -> None: ... def add_states(self, state_classes: Sequence[type[State[_Context]]]) -> None: ... def runtime_init(self) -> None: ... @@ -67,24 +69,16 @@ class State(Generic[_Context]): def remove_transition(self, name: str) -> None: ... def make_transition( self, name: str, next_state: str | None = None - ) -> tuple[Pattern[str], Callable[[Match[str], _Context, str], tuple[_Context, str | None, list[str]]], str]: ... + ) -> tuple[Pattern[str], _TransitionMethod[_Context], str]: ... def make_transitions( self, name_list: list[str | tuple[str] | tuple[str, str]] - ) -> tuple[ - list[str], - dict[str, tuple[Pattern[str], Callable[[Match[str], _Context, str], tuple[_Context, str | None, list[str]]], str]], - ]: ... + ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]]: ... def no_match( - self, - context: Any, - transitions: tuple[ - list[str], - dict[str, tuple[Pattern[str], Callable[[Match[str], _Context, str], tuple[_Context, str | None, list[str]]], str]], - ], - ) -> tuple[_Context, str | None, list[str]]: ... + self, context: Any, transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]] + ) -> _TransitionResult[_Context]: ... def bof(self, context: _Context) -> tuple[_Context, list[str]]: ... def eof(self, context: _Context) -> list[str]: ... - def nop(self, match: Match[str], context: _Context, next_state: str) -> tuple[_Context, str | None, list[str]]: ... + def nop(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... class StateMachineWS(StateMachine[_Context]): def get_indented(self, until_blank: bool = False, strip_indent: bool = True) -> tuple[StringList, int, int, bool]: ... @@ -104,12 +98,10 @@ class StateWS(State[_Context]): ws_initial_transitions: Sequence[str] def __init__(self, state_machine: StateMachine[_Context], debug: bool = False) -> None: ... def add_initial_transitions(self) -> None: ... - def blank(self, match: Match[str], context: _Context, next_state: str) -> tuple[_Context, str | None, list[str]]: ... - def indent(self, match: Match[str], context: _Context, next_state: str) -> tuple[_Context, str | None, list[str]]: ... - def known_indent(self, match: Match[str], context: _Context, next_state: str) -> tuple[_Context, str | None, list[str]]: ... - def first_known_indent( - self, match: Match[str], context: _Context, next_state: str - ) -> tuple[_Context, str | None, list[str]]: ... + def blank(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def first_known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... class _SearchOverride: def match(self, pattern: Pattern[str]) -> Match[str]: ... From 571a5fbba09f69fef71377f3f262e53f04206a2d Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sat, 2 Mar 2024 15:01:18 +0000 Subject: [PATCH 06/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index cc9a4c50a523..4b4e04a50ec7 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable, Generator, Iterator, Sequence from re import Match, Pattern -from typing import Any, Generic, TypeAlias, TypeVar, overload -from typing_extensions import Self +from typing import Any, Generic, TypeVar, overload +from typing_extensions import Self, TypeAlias _Context = TypeVar("_Context") _TransitionResult: TypeAlias = tuple[_Context, str | None, list[str]] From 727538eb761f384efa13fbc107a07b9a7344fcf9 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 3 Mar 2024 20:45:11 +0000 Subject: [PATCH 07/26] fixup --- 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 0bdf6a5c0f8b..9c7336c33213 100644 --- a/stubs/docutils/@tests/stubtest_allowlist.txt +++ b/stubs/docutils/@tests/stubtest_allowlist.txt @@ -10,7 +10,7 @@ docutils.nodes.GenericNodeVisitor.__getattr__ # these methods take a rawsource parameter that has been deprecated and is completely ignored, so we omit it from the stub docutils.nodes.Text.__new__ docutils.parsers.recommonmark_wrapper -docutils.parsers.rst.directives.misc.MetaBody.__getattr__ +docutils.statemachine.ViewList.__iter__ # doesn't exist at runtime, but the class is iterable due to __getitem__ docutils.transforms.Transform.__getattr__ docutils.transforms.Transformer.__getattr__ docutils.TransformSpec.unknown_reference_resolvers From e92684fdf3991e958b91dfe61b1a0593365c882c Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 3 Mar 2024 21:10:08 +0000 Subject: [PATCH 08/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 67 ++++++++++++------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 4b4e04a50ec7..b479ed6b6261 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -3,21 +3,20 @@ from re import Match, Pattern from typing import Any, Generic, TypeVar, overload from typing_extensions import Self, TypeAlias -_Context = TypeVar("_Context") -_TransitionResult: TypeAlias = tuple[_Context, str | None, list[str]] -_TransitionMethod: TypeAlias = Callable[[Match[str], _Context, str], _TransitionResult[_Context]] +_TransitionResult: TypeAlias = tuple[Any, str | None, list[str]] +_TransitionMethod: TypeAlias = Callable[[Match[str], Any, str], _TransitionResult] -class StateMachine(Generic[_Context]): +class StateMachine: input_lines: StringList | None input_offset: int line: str | None line_offset: int debug: bool initial_state: str - current_state: list[State[_Context]] - states: dict[str, State[_Context]] + current_state: list[State] + states: dict[str, State] observers: list[Callable[[Self], None]] - def __init__(self, state_classes: Sequence[type[State[_Context]]], initial_state: str, debug: bool = False) -> None: ... + def __init__(self, state_classes: Sequence[type[State]], initial_state: str, debug: bool = False) -> None: ... def unlink(self) -> None: ... def run( self, @@ -27,7 +26,7 @@ class StateMachine(Generic[_Context]): input_source: str | None = None, initial_state: str | None = None, ) -> list[Any]: ... - def get_state(self, next_state: str | None = None) -> State[_Context]: ... + def get_state(self, next_state: str | None = None) -> State: ... def next_line(self, n: int = 1) -> str: ... def is_next_line_blank(self) -> bool: ... def at_eof(self) -> bool: ... @@ -41,26 +40,26 @@ class StateMachine(Generic[_Context]): def insert_input(self, input_lines: list[str] | StringList, source: str) -> None: ... def get_text_block(self, flush_left: bool = False) -> StringList: ... def check_line( - self, context: _Context, state: State[_Context], transitions: list[str] | None = ... - ) -> _TransitionResult[_Context]: ... - def add_state(self, state_class: type[State[_Context]]) -> None: ... - def add_states(self, state_classes: Sequence[type[State[_Context]]]) -> None: ... + self, context: Any, state: State, transitions: list[str] | None = ... + ) -> _TransitionResult: ... + def add_state(self, state_class: type[State]) -> None: ... + def add_states(self, state_classes: Sequence[type[State]]) -> None: ... def runtime_init(self) -> None: ... def error(self) -> None: ... def attach_observer(self, observer) -> None: ... def detach_observer(self, observer) -> None: ... def notify_observers(self) -> None: ... -class State(Generic[_Context]): +class State: patterns: dict[str, str | Pattern[str]] | None initial_transitions: Sequence[str] | Sequence[tuple[str, str]] | None - nested_sm: type[StateMachine[_Context]] | None + nested_sm: type[StateMachine] | None nested_sm_kwargs: dict[str, Any] | None transition_order: list[str] transitions: dict[str, tuple[Pattern[str], Callable[[], None], str]] - state_machine: StateMachine[_Context] + state_machine: StateMachine debug: bool - def __init__(self, state_machine: StateMachine[_Context], debug: bool = False) -> None: ... + def __init__(self, state_machine: StateMachine, debug: bool = False) -> None: ... def runtime_init(self) -> None: ... def unlink(self) -> None: ... def add_initial_transitions(self) -> None: ... @@ -69,18 +68,18 @@ class State(Generic[_Context]): def remove_transition(self, name: str) -> None: ... def make_transition( self, name: str, next_state: str | None = None - ) -> tuple[Pattern[str], _TransitionMethod[_Context], str]: ... + ) -> tuple[Pattern[str], _TransitionMethod, str]: ... def make_transitions( self, name_list: list[str | tuple[str] | tuple[str, str]] - ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]]: ... + ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod, str]]]: ... def no_match( - self, context: Any, transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]] - ) -> _TransitionResult[_Context]: ... - def bof(self, context: _Context) -> tuple[_Context, list[str]]: ... - def eof(self, context: _Context) -> list[str]: ... - def nop(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + self, context: Any, transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod, str]]] + ) -> _TransitionResult: ... + def bof(self, context: Any) -> tuple[Any, list[str]]: ... + def eof(self, context: Any) -> list[str]: ... + def nop(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... -class StateMachineWS(StateMachine[_Context]): +class StateMachineWS(StateMachine): def get_indented(self, until_blank: bool = False, strip_indent: bool = True) -> tuple[StringList, int, int, bool]: ... def get_known_indented( self, indent: int, until_blank: bool = False, strip_indent: bool = True @@ -89,25 +88,25 @@ class StateMachineWS(StateMachine[_Context]): self, indent: int, until_blank: bool = False, strip_indent: bool = True, strip_top: bool = True ) -> tuple[list[str], int, int, bool]: ... -class StateWS(State[_Context]): - indent_sm: type[StateMachine[_Context]] | None +class StateWS(State): + indent_sm: type[StateMachine] | None indent_sm_kwargs: dict[str, Any] | None - known_indent_sm: type[StateMachine[_Context]] | None + known_indent_sm: type[StateMachine] | None known_indent_sm_kwargs: dict[str, Any] | None ws_patterns: dict[str, str] ws_initial_transitions: Sequence[str] - def __init__(self, state_machine: StateMachine[_Context], debug: bool = False) -> None: ... + def __init__(self, state_machine: StateMachine, debug: bool = False) -> None: ... def add_initial_transitions(self) -> None: ... - def blank(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... - def indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... - def known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... - def first_known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def blank(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... + def indent(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... + def known_indent(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... + def first_known_indent(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... class _SearchOverride: def match(self, pattern: Pattern[str]) -> Match[str]: ... -class SearchStateMachine(_SearchOverride, StateMachine[_Context]): ... -class SearchStateMachineWS(_SearchOverride, StateMachineWS[_Context]): ... +class SearchStateMachine(_SearchOverride, StateMachine): ... +class SearchStateMachineWS(_SearchOverride, StateMachineWS): ... _Data = TypeVar("_Data") From 84155462665c7139c449ffb2872d7bcdadc0bf85 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:11:00 +0000 Subject: [PATCH 09/26] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/docutils/docutils/statemachine.pyi | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index b479ed6b6261..30adf12d6c44 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -39,9 +39,7 @@ class StateMachine: def get_source_and_line(self, lineno: int | None = None) -> tuple[str, int]: ... def insert_input(self, input_lines: list[str] | StringList, source: str) -> None: ... def get_text_block(self, flush_left: bool = False) -> StringList: ... - def check_line( - self, context: Any, state: State, transitions: list[str] | None = ... - ) -> _TransitionResult: ... + def check_line(self, context: Any, state: State, transitions: list[str] | None = ...) -> _TransitionResult: ... def add_state(self, state_class: type[State]) -> None: ... def add_states(self, state_classes: Sequence[type[State]]) -> None: ... def runtime_init(self) -> None: ... @@ -66,9 +64,7 @@ class State: def add_transitions(self, names: list[str], transitions) -> None: ... def add_transition(self, name: str, transition: tuple[Pattern[str], str, str]) -> None: ... def remove_transition(self, name: str) -> None: ... - def make_transition( - self, name: str, next_state: str | None = None - ) -> tuple[Pattern[str], _TransitionMethod, str]: ... + def make_transition(self, name: str, next_state: str | None = None) -> tuple[Pattern[str], _TransitionMethod, str]: ... def make_transitions( self, name_list: list[str | tuple[str] | tuple[str, str]] ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod, str]]]: ... From 36e175da8c1044d433f7a9f45306187fea8fbf65 Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Mon, 4 Mar 2024 08:00:55 +0000 Subject: [PATCH 10/26] use 'str' instead of 'Any' for context --- stubs/docutils/docutils/statemachine.pyi | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 30adf12d6c44..d5704a16200c 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -3,8 +3,8 @@ from re import Match, Pattern from typing import Any, Generic, TypeVar, overload from typing_extensions import Self, TypeAlias -_TransitionResult: TypeAlias = tuple[Any, str | None, list[str]] -_TransitionMethod: TypeAlias = Callable[[Match[str], Any, str], _TransitionResult] +_TransitionResult: TypeAlias = tuple[list[str], str | None, list[str]] +_TransitionMethod: TypeAlias = Callable[[Match[str], list[str], str], _TransitionResult] class StateMachine: input_lines: StringList | None @@ -22,10 +22,10 @@ class StateMachine: self, input_lines: list[str] | StringList, input_offset: int = 0, - context: Any | None = None, + context: list[str] | None = None, input_source: str | None = None, initial_state: str | None = None, - ) -> list[Any]: ... + ) -> list[str]: ... def get_state(self, next_state: str | None = None) -> State: ... def next_line(self, n: int = 1) -> str: ... def is_next_line_blank(self) -> bool: ... @@ -39,7 +39,7 @@ class StateMachine: def get_source_and_line(self, lineno: int | None = None) -> tuple[str, int]: ... def insert_input(self, input_lines: list[str] | StringList, source: str) -> None: ... def get_text_block(self, flush_left: bool = False) -> StringList: ... - def check_line(self, context: Any, state: State, transitions: list[str] | None = ...) -> _TransitionResult: ... + def check_line(self, context: list[str], state: State, transitions: list[str] | None = ...) -> _TransitionResult: ... def add_state(self, state_class: type[State]) -> None: ... def add_states(self, state_classes: Sequence[type[State]]) -> None: ... def runtime_init(self) -> None: ... @@ -69,11 +69,11 @@ class State: self, name_list: list[str | tuple[str] | tuple[str, str]] ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod, str]]]: ... def no_match( - self, context: Any, transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod, str]]] + self, context: list[str], transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod, str]]] ) -> _TransitionResult: ... - def bof(self, context: Any) -> tuple[Any, list[str]]: ... - def eof(self, context: Any) -> list[str]: ... - def nop(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... + def bof(self, context: list[str]) -> tuple[list[str], list[str]]: ... + def eof(self, context: list[str]) -> list[str]: ... + def nop(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... class StateMachineWS(StateMachine): def get_indented(self, until_blank: bool = False, strip_indent: bool = True) -> tuple[StringList, int, int, bool]: ... @@ -93,10 +93,10 @@ class StateWS(State): ws_initial_transitions: Sequence[str] def __init__(self, state_machine: StateMachine, debug: bool = False) -> None: ... def add_initial_transitions(self) -> None: ... - def blank(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... - def indent(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... - def known_indent(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... - def first_known_indent(self, match: Match[str], context: Any, next_state: str) -> _TransitionResult: ... + def blank(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... + def indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... + def known_indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... + def first_known_indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... class _SearchOverride: def match(self, pattern: Pattern[str]) -> Match[str]: ... @@ -140,7 +140,7 @@ class ViewList(Generic[_Data]): def __radd__(self, other: ViewList[_Data]) -> None: ... def __iadd__(self, other: Self) -> Self: ... def __mul__(self, n: int) -> ViewList[_Data]: ... - __rmul__: Any = ... + __rmul__: Any def __imul__(self, n: int) -> Self: ... def extend(self, other: ViewList[_Data]) -> None: ... def append(self, item: _Data, source: str | None = None, offset: int = 0) -> None: ... From 6d1fd79f53539a42cf88c1d0917dbfd7331b19ec Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Mon, 4 Mar 2024 14:55:00 +0000 Subject: [PATCH 11/26] address some comments --- stubs/docutils/docutils/statemachine.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index d5704a16200c..c85c11b97c9e 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -13,7 +13,7 @@ class StateMachine: line_offset: int debug: bool initial_state: str - current_state: list[State] + current_state: str states: dict[str, State] observers: list[Callable[[Self], None]] def __init__(self, state_classes: Sequence[type[State]], initial_state: str, debug: bool = False) -> None: ... @@ -31,12 +31,12 @@ class StateMachine: def is_next_line_blank(self) -> bool: ... def at_eof(self) -> bool: ... def at_bof(self) -> bool: ... - def previous_line(self, n: int = 1) -> str: ... - def goto_line(self, line_offset: int) -> None: ... + def previous_line(self, n: int = 1) -> str | None: ... + def goto_line(self, line_offset: int) -> str | None: ... def get_source(self, line_offset: int) -> str: ... def abs_line_offset(self) -> int: ... def abs_line_number(self) -> int: ... - def get_source_and_line(self, lineno: int | None = None) -> tuple[str, int]: ... + def get_source_and_line(self, lineno: int | None = None) -> tuple[str, int] | tuple[None, None]: ... def insert_input(self, input_lines: list[str] | StringList, source: str) -> None: ... def get_text_block(self, flush_left: bool = False) -> StringList: ... def check_line(self, context: list[str], state: State, transitions: list[str] | None = ...) -> _TransitionResult: ... From 02eea078c62d813506581a20d007f0d2db64c021 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Tue, 5 Mar 2024 21:16:38 +0000 Subject: [PATCH 12/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index c85c11b97c9e..2cc96d3331a8 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -140,7 +140,7 @@ class ViewList(Generic[_Data]): def __radd__(self, other: ViewList[_Data]) -> None: ... def __iadd__(self, other: Self) -> Self: ... def __mul__(self, n: int) -> ViewList[_Data]: ... - __rmul__: Any + def __rmul__(self, n: int) -> ViewList[_Data]: ... def __imul__(self, n: int) -> Self: ... def extend(self, other: ViewList[_Data]) -> None: ... def append(self, item: _Data, source: str | None = None, offset: int = 0) -> None: ... From b2336922565f53739fca09b60dcafc31cd2eee12 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Tue, 5 Mar 2024 21:17:48 +0000 Subject: [PATCH 13/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 2cc96d3331a8..5e8c757a547f 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -153,7 +153,7 @@ class ViewList(Generic[_Data]): def index(self, item: _Data) -> int: ... def reverse(self) -> None: ... def sort(self, *args: tuple[_Data, tuple[str, int]]) -> None: ... - def info(self, i: int) -> tuple[str, int]: ... + def info(self, i: int) -> tuple[str, int | None]: ... def source(self, i: int) -> str: ... def offset(self, i: int) -> int: ... def disconnect(self) -> None: ... From ccb7786c67531a168504394a1c7ac3269583be8c Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Fri, 8 Mar 2024 07:32:52 +0000 Subject: [PATCH 14/26] fixup --- stubs/docutils/docutils/parsers/rst/tableparser.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stubs/docutils/docutils/parsers/rst/tableparser.pyi b/stubs/docutils/docutils/parsers/rst/tableparser.pyi index 76b06eb90532..2759321df26c 100644 --- a/stubs/docutils/docutils/parsers/rst/tableparser.pyi +++ b/stubs/docutils/docutils/parsers/rst/tableparser.pyi @@ -3,7 +3,7 @@ from typing import ClassVar from typing_extensions import TypeAlias from docutils import DataError -from docutils.statemachine import Stringlist +from docutils.statemachine import StringList _Cell: TypeAlias = tuple[int, int, int, list[str]] _Row: TypeAlias = list[_Cell | None] @@ -18,12 +18,12 @@ class TableMarkupError(DataError): 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 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 + block: StringList bottom: int right: int head_body_sep: int @@ -31,7 +31,7 @@ class GridTableParser(TableParser): cells: list[_Cell] rowseps: dict[int, list[int]] colseps: dict[int, list[int]] - def setup(self, block: Stringlist) -> None: ... + 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: ... @@ -45,7 +45,7 @@ class GridTableParser(TableParser): class SimpleTableParser(TableParser): head_body_separator_pat: ClassVar[Pattern[str]] span_pat: ClassVar[Pattern[str]] - block: Stringlist + block: StringList head_body_sep: int columns: list[tuple[int, int]] border_end: int @@ -53,7 +53,7 @@ class SimpleTableParser(TableParser): done: list[int] rowseps: dict[int, tuple[int]] colseps: dict[int, tuple[int]] - def setup(self, block: Stringlist) -> None: ... + 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]: ... From 3281ae22356a046946e1843cd7f9464f89692c8b Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Sun, 10 Mar 2024 17:18:02 +0000 Subject: [PATCH 15/26] Apply suggestions from code review Co-authored-by: Sebastian Rittau --- stubs/docutils/docutils/statemachine.pyi | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 5e8c757a547f..d0b5fd5ac2a0 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -16,11 +16,11 @@ class StateMachine: current_state: str states: dict[str, State] observers: list[Callable[[Self], None]] - def __init__(self, state_classes: Sequence[type[State]], initial_state: str, debug: bool = False) -> None: ... + def __init__(self, state_classes: Iterable[type[State]], initial_state: str, debug: bool = False) -> None: ... def unlink(self) -> None: ... def run( self, - input_lines: list[str] | StringList, + input_lines: Sequence[str] | StringList, input_offset: int = 0, context: list[str] | None = None, input_source: str | None = None, @@ -41,7 +41,7 @@ class StateMachine: def get_text_block(self, flush_left: bool = False) -> StringList: ... def check_line(self, context: list[str], state: State, transitions: list[str] | None = ...) -> _TransitionResult: ... def add_state(self, state_class: type[State]) -> None: ... - def add_states(self, state_classes: Sequence[type[State]]) -> None: ... + def add_states(self, state_classes: Iterable[type[State]]) -> None: ... def runtime_init(self) -> None: ... def error(self) -> None: ... def attach_observer(self, observer) -> None: ... @@ -49,8 +49,8 @@ class StateMachine: def notify_observers(self) -> None: ... class State: - patterns: dict[str, str | Pattern[str]] | None - initial_transitions: Sequence[str] | Sequence[tuple[str, str]] | None + patterns: ClassVar[dict[str, str | Pattern[str]] | None] + initial_transitions: ClassVar[Sequence[str] | Sequence[tuple[str, str]] | None] nested_sm: type[StateMachine] | None nested_sm_kwargs: dict[str, Any] | None transition_order: list[str] @@ -61,7 +61,7 @@ class State: def runtime_init(self) -> None: ... def unlink(self) -> None: ... def add_initial_transitions(self) -> None: ... - def add_transitions(self, names: list[str], transitions) -> None: ... + def add_transitions(self, names: Iterable[str], transitions) -> None: ... def add_transition(self, name: str, transition: tuple[Pattern[str], str, str]) -> None: ... def remove_transition(self, name: str) -> None: ... def make_transition(self, name: str, next_state: str | None = None) -> tuple[Pattern[str], _TransitionMethod, str]: ... @@ -89,7 +89,7 @@ class StateWS(State): indent_sm_kwargs: dict[str, Any] | None known_indent_sm: type[StateMachine] | None known_indent_sm_kwargs: dict[str, Any] | None - ws_patterns: dict[str, str] + ws_patterns: dict[str, Pattern[str]] ws_initial_transitions: Sequence[str] def __init__(self, state_machine: StateMachine, debug: bool = False) -> None: ... def add_initial_transitions(self) -> None: ... @@ -113,7 +113,7 @@ class ViewList(Generic[_Data]): parent_offset: int def __init__( self, - initlist: ViewList[_Data] | list[_Data] | None = None, + initlist: ViewList[_Data] | Sequence[_Data] | None = None, source: str | None = None, items: list[tuple[str, int]] | None = None, parent: ViewList[_Data] | None = None, @@ -130,17 +130,17 @@ class ViewList(Generic[_Data]): @overload def __getitem__(self, i: slice) -> ViewList[_Data]: ... @overload - def __getitem__(self, i: int) -> _Data: ... + def __getitem__(self, i: SupportsIndex) -> _Data: ... @overload def __setitem__(self, i: slice, item: ViewList[_Data]) -> None: ... @overload - def __setitem__(self, i: int, item: _Data) -> None: ... - def __delitem__(self, i: int) -> None: ... - def __add__(self, other: ViewList[_Data]) -> None: ... - def __radd__(self, other: ViewList[_Data]) -> None: ... - def __iadd__(self, other: Self) -> Self: ... - def __mul__(self, n: int) -> ViewList[_Data]: ... - def __rmul__(self, n: int) -> ViewList[_Data]: ... + def __setitem__(self, i: SupportsIndex, item: _Data) -> None: ... + def __delitem__(self, i: SupportsIndex) -> None: ... + def __add__(self, other: ViewList[_Data]) -> Self: ... + def __radd__(self, other: ViewList[_Data]) -> Self: ... + def __iadd__(self, other: ViewList[_Data]) -> Self: ... + def __mul__(self, n: int) -> Self: ... + __rmul__ = __mul__ def __imul__(self, n: int) -> Self: ... def extend(self, other: ViewList[_Data]) -> None: ... def append(self, item: _Data, source: str | None = None, offset: int = 0) -> None: ... From 9283536aea085e88739bde97a33ac545a2021423 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 10 Mar 2024 17:20:47 +0000 Subject: [PATCH 16/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index d0b5fd5ac2a0..4fb78d5a5b3a 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,6 +1,6 @@ from collections.abc import Callable, Generator, Iterator, Sequence from re import Match, Pattern -from typing import Any, Generic, TypeVar, overload +from typing import Any, ClassVar, Generic, Iterable, SupportsIndex, TypeVar, overload from typing_extensions import Self, TypeAlias _TransitionResult: TypeAlias = tuple[list[str], str | None, list[str]] From 765974b30b6d8b160b386c71e5b4deb21cd48b2b Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 10 Mar 2024 17:29:54 +0000 Subject: [PATCH 17/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 112 ++++++++++++----------- 1 file changed, 58 insertions(+), 54 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 4fb78d5a5b3a..8107a6f4bef6 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,12 +1,14 @@ -from collections.abc import Callable, Generator, Iterator, Sequence +from collections.abc import Callable, Generator, Iterable, Iterator, Sequence from re import Match, Pattern -from typing import Any, ClassVar, Generic, Iterable, SupportsIndex, TypeVar, overload +from typing import Any, ClassVar, Generic, SupportsIndex, TypeVar, overload from typing_extensions import Self, TypeAlias -_TransitionResult: TypeAlias = tuple[list[str], str | None, list[str]] -_TransitionMethod: TypeAlias = Callable[[Match[str], list[str], str], _TransitionResult] +_T = TypeVar("_T") +_Context = TypeVar("_Context") +_TransitionResult: TypeAlias = tuple[_Context, str | None, list[str]] +_TransitionMethod: TypeAlias = Callable[[Match[str], _Context, str], _TransitionResult[_Context]] -class StateMachine: +class StateMachine(Generic[_Context]): input_lines: StringList | None input_offset: int line: str | None @@ -14,9 +16,9 @@ class StateMachine: debug: bool initial_state: str current_state: str - states: dict[str, State] + states: dict[str, State[_Context]] observers: list[Callable[[Self], None]] - def __init__(self, state_classes: Iterable[type[State]], initial_state: str, debug: bool = False) -> None: ... + def __init__(self, state_classes: Iterable[type[State[_Context]]], initial_state: str, debug: bool = False) -> None: ... def unlink(self) -> None: ... def run( self, @@ -26,7 +28,7 @@ class StateMachine: input_source: str | None = None, initial_state: str | None = None, ) -> list[str]: ... - def get_state(self, next_state: str | None = None) -> State: ... + def get_state(self, next_state: str | None = None) -> State[_Context]: ... def next_line(self, n: int = 1) -> str: ... def is_next_line_blank(self) -> bool: ... def at_eof(self) -> bool: ... @@ -39,43 +41,47 @@ class StateMachine: def get_source_and_line(self, lineno: int | None = None) -> tuple[str, int] | tuple[None, None]: ... def insert_input(self, input_lines: list[str] | StringList, source: str) -> None: ... def get_text_block(self, flush_left: bool = False) -> StringList: ... - def check_line(self, context: list[str], state: State, transitions: list[str] | None = ...) -> _TransitionResult: ... - def add_state(self, state_class: type[State]) -> None: ... - def add_states(self, state_classes: Iterable[type[State]]) -> None: ... + def check_line( + self, context: list[str], state: State[_Context], transitions: list[str] | None = ... + ) -> _TransitionResult[_Context]: ... + def add_state(self, state_class: type[State[_Context]]) -> None: ... + def add_states(self, state_classes: Iterable[type[State[_Context]]]) -> None: ... def runtime_init(self) -> None: ... def error(self) -> None: ... def attach_observer(self, observer) -> None: ... def detach_observer(self, observer) -> None: ... def notify_observers(self) -> None: ... -class State: +class State(Generic[_Context]): patterns: ClassVar[dict[str, str | Pattern[str]] | None] initial_transitions: ClassVar[Sequence[str] | Sequence[tuple[str, str]] | None] - nested_sm: type[StateMachine] | None + nested_sm: type[StateMachine[_Context]] | None nested_sm_kwargs: dict[str, Any] | None transition_order: list[str] transitions: dict[str, tuple[Pattern[str], Callable[[], None], str]] - state_machine: StateMachine + state_machine: StateMachine[_Context] debug: bool - def __init__(self, state_machine: StateMachine, debug: bool = False) -> None: ... + def __init__(self, state_machine: StateMachine[_Context], debug: bool = False) -> None: ... def runtime_init(self) -> None: ... def unlink(self) -> None: ... def add_initial_transitions(self) -> None: ... def add_transitions(self, names: Iterable[str], transitions) -> None: ... def add_transition(self, name: str, transition: tuple[Pattern[str], str, str]) -> None: ... def remove_transition(self, name: str) -> None: ... - def make_transition(self, name: str, next_state: str | None = None) -> tuple[Pattern[str], _TransitionMethod, str]: ... + def make_transition( + self, name: str, next_state: str | None = None + ) -> tuple[Pattern[str], _TransitionMethod[_Context], str]: ... def make_transitions( self, name_list: list[str | tuple[str] | tuple[str, str]] - ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod, str]]]: ... + ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]]: ... def no_match( - self, context: list[str], transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod, str]]] - ) -> _TransitionResult: ... + self, context: list[str], transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]] + ) -> _TransitionResult[_Context]: ... def bof(self, context: list[str]) -> tuple[list[str], list[str]]: ... def eof(self, context: list[str]) -> list[str]: ... - def nop(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... + def nop(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... -class StateMachineWS(StateMachine): +class StateMachineWS(StateMachine[_Context]): def get_indented(self, until_blank: bool = False, strip_indent: bool = True) -> tuple[StringList, int, int, bool]: ... def get_known_indented( self, indent: int, until_blank: bool = False, strip_indent: bool = True @@ -84,39 +90,37 @@ class StateMachineWS(StateMachine): self, indent: int, until_blank: bool = False, strip_indent: bool = True, strip_top: bool = True ) -> tuple[list[str], int, int, bool]: ... -class StateWS(State): - indent_sm: type[StateMachine] | None +class StateWS(State[_Context]): + indent_sm: type[StateMachine[_Context]] | None indent_sm_kwargs: dict[str, Any] | None - known_indent_sm: type[StateMachine] | None + known_indent_sm: type[StateMachine[_Context]] | None known_indent_sm_kwargs: dict[str, Any] | None ws_patterns: dict[str, Pattern[str]] ws_initial_transitions: Sequence[str] - def __init__(self, state_machine: StateMachine, debug: bool = False) -> None: ... + def __init__(self, state_machine: StateMachine[_Context], debug: bool = False) -> None: ... def add_initial_transitions(self) -> None: ... - def blank(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... - def indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... - def known_indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... - def first_known_indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult: ... + def blank(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... + def indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... + def known_indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... + def first_known_indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... class _SearchOverride: def match(self, pattern: Pattern[str]) -> Match[str]: ... -class SearchStateMachine(_SearchOverride, StateMachine): ... -class SearchStateMachineWS(_SearchOverride, StateMachineWS): ... +class SearchStateMachine(_SearchOverride, StateMachine[_Context]): ... +class SearchStateMachineWS(_SearchOverride, StateMachineWS[_Context]): ... -_Data = TypeVar("_Data") - -class ViewList(Generic[_Data]): - data: list[_Data] +class ViewList(Generic[_T]): + data: list[_T] items: list[tuple[str, int]] - parent: ViewList[_Data] + parent: ViewList[_T] parent_offset: int def __init__( self, - initlist: ViewList[_Data] | Sequence[_Data] | None = None, + initlist: ViewList[_T] | Sequence[_T] | None = None, source: str | None = None, items: list[tuple[str, int]] | None = None, - parent: ViewList[_Data] | None = None, + parent: ViewList[_T] | None = None, parent_offset: int | None = None, ) -> None: ... def __lt__(self, other: Any) -> bool: ... @@ -125,34 +129,34 @@ class ViewList(Generic[_Data]): def __ne__(self, other: object) -> bool: ... def __gt__(self, other: Any) -> bool: ... def __ge__(self, other: Any) -> bool: ... - def __contains__(self, item: ViewList[_Data]) -> bool: ... + def __contains__(self, item: ViewList[_T]) -> bool: ... def __len__(self) -> int: ... @overload - def __getitem__(self, i: slice) -> ViewList[_Data]: ... + def __getitem__(self, i: slice) -> ViewList[_T]: ... @overload - def __getitem__(self, i: SupportsIndex) -> _Data: ... + def __getitem__(self, i: SupportsIndex) -> _T: ... @overload - def __setitem__(self, i: slice, item: ViewList[_Data]) -> None: ... + def __setitem__(self, i: slice, item: ViewList[_T]) -> None: ... @overload - def __setitem__(self, i: SupportsIndex, item: _Data) -> None: ... + def __setitem__(self, i: SupportsIndex, item: _T) -> None: ... def __delitem__(self, i: SupportsIndex) -> None: ... - def __add__(self, other: ViewList[_Data]) -> Self: ... - def __radd__(self, other: ViewList[_Data]) -> Self: ... - def __iadd__(self, other: ViewList[_Data]) -> Self: ... + def __add__(self, other: ViewList[_T]) -> Self: ... + def __radd__(self, other: ViewList[_T]) -> Self: ... + def __iadd__(self, other: ViewList[_T]) -> Self: ... def __mul__(self, n: int) -> Self: ... __rmul__ = __mul__ def __imul__(self, n: int) -> Self: ... - def extend(self, other: ViewList[_Data]) -> None: ... - def append(self, item: _Data, source: str | None = None, offset: int = 0) -> None: ... - def insert(self, i: int, item: _Data, source: str | None = None, offset: int = 0) -> None: ... - def pop(self, i: int = -1) -> _Data: ... + def extend(self, other: ViewList[_T]) -> None: ... + def append(self, item: _T, source: str | None = None, offset: int = 0) -> None: ... + def insert(self, i: int, item: _T, source: str | None = None, offset: int = 0) -> None: ... + def pop(self, i: int = -1) -> _T: ... def trim_start(self, n: int = 1) -> None: ... def trim_end(self, n: int = 1) -> None: ... - def remove(self, item: _Data) -> None: ... - def count(self, item: _Data) -> int: ... - def index(self, item: _Data) -> int: ... + def remove(self, item: _T) -> None: ... + def count(self, item: _T) -> int: ... + def index(self, item: _T) -> int: ... def reverse(self) -> None: ... - def sort(self, *args: tuple[_Data, tuple[str, int]]) -> None: ... + def sort(self, *args: tuple[_T, tuple[str, int]]) -> None: ... def info(self, i: int) -> tuple[str, int | None]: ... def source(self, i: int) -> str: ... def offset(self, i: int) -> int: ... From 783d513a1e5b4b06d3b3ddc2bb99cf9309efc111 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 10 Mar 2024 17:30:09 +0000 Subject: [PATCH 18/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 8107a6f4bef6..3d4f8647cef1 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -24,7 +24,7 @@ class StateMachine(Generic[_Context]): self, input_lines: Sequence[str] | StringList, input_offset: int = 0, - context: list[str] | None = None, + context: _Context | None = None, input_source: str | None = None, initial_state: str | None = None, ) -> list[str]: ... @@ -42,7 +42,7 @@ class StateMachine(Generic[_Context]): def insert_input(self, input_lines: list[str] | StringList, source: str) -> None: ... def get_text_block(self, flush_left: bool = False) -> StringList: ... def check_line( - self, context: list[str], state: State[_Context], transitions: list[str] | None = ... + self, context: _Context, state: State[_Context], transitions: list[str] | None = ... ) -> _TransitionResult[_Context]: ... def add_state(self, state_class: type[State[_Context]]) -> None: ... def add_states(self, state_classes: Iterable[type[State[_Context]]]) -> None: ... @@ -75,11 +75,11 @@ class State(Generic[_Context]): self, name_list: list[str | tuple[str] | tuple[str, str]] ) -> tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]]: ... def no_match( - self, context: list[str], transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]] + self, context: _Context, transitions: tuple[list[str], dict[str, tuple[Pattern[str], _TransitionMethod[_Context], str]]] ) -> _TransitionResult[_Context]: ... - def bof(self, context: list[str]) -> tuple[list[str], list[str]]: ... - def eof(self, context: list[str]) -> list[str]: ... - def nop(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... + def bof(self, context: _Context) -> tuple[list[str], list[str]]: ... + def eof(self, context: _Context) -> list[str]: ... + def nop(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... class StateMachineWS(StateMachine[_Context]): def get_indented(self, until_blank: bool = False, strip_indent: bool = True) -> tuple[StringList, int, int, bool]: ... @@ -99,10 +99,10 @@ class StateWS(State[_Context]): ws_initial_transitions: Sequence[str] def __init__(self, state_machine: StateMachine[_Context], debug: bool = False) -> None: ... def add_initial_transitions(self) -> None: ... - def blank(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... - def indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... - def known_indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... - def first_known_indent(self, match: Match[str], context: list[str], next_state: str) -> _TransitionResult[_Context]: ... + def blank(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... + def first_known_indent(self, match: Match[str], context: _Context, next_state: str) -> _TransitionResult[_Context]: ... class _SearchOverride: def match(self, pattern: Pattern[str]) -> Match[str]: ... From 0241ebe51e0915b96105b655d20f5f263513db34 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 10 Mar 2024 18:48:30 +0000 Subject: [PATCH 19/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 3d4f8647cef1..af3f7f194c74 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -55,8 +55,8 @@ class StateMachine(Generic[_Context]): class State(Generic[_Context]): patterns: ClassVar[dict[str, str | Pattern[str]] | None] initial_transitions: ClassVar[Sequence[str] | Sequence[tuple[str, str]] | None] - nested_sm: type[StateMachine[_Context]] | None - nested_sm_kwargs: dict[str, Any] | None + nested_sm: type[StateMachine[_Context]] + nested_sm_kwargs: dict[str, Any] transition_order: list[str] transitions: dict[str, tuple[Pattern[str], Callable[[], None], str]] state_machine: StateMachine[_Context] From e4b19d51c7872e33a6dd0f244791c498ab10a6e2 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 10 Mar 2024 19:03:15 +0000 Subject: [PATCH 20/26] fixup --- stubs/docutils/@tests/stubtest_allowlist.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/docutils/@tests/stubtest_allowlist.txt b/stubs/docutils/@tests/stubtest_allowlist.txt index 9c7336c33213..78233e17e0f8 100644 --- a/stubs/docutils/@tests/stubtest_allowlist.txt +++ b/stubs/docutils/@tests/stubtest_allowlist.txt @@ -10,6 +10,8 @@ docutils.nodes.GenericNodeVisitor.__getattr__ # these methods take a rawsource parameter that has been deprecated and is completely ignored, so we omit it from the stub docutils.nodes.Text.__new__ docutils.parsers.recommonmark_wrapper +docutils.statemachine.State.nested_sm # is initialised in __init__ +docutils.statemachine.State.nested_sm_kwargs # is initialised in __init__ docutils.statemachine.ViewList.__iter__ # doesn't exist at runtime, but the class is iterable due to __getitem__ docutils.transforms.Transform.__getattr__ docutils.transforms.Transformer.__getattr__ From de8e97379c966add6b04a0b142c2d2989f664441 Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Mon, 11 Mar 2024 14:27:27 +0000 Subject: [PATCH 21/26] add 'observer' type alias --- stubs/docutils/docutils/statemachine.pyi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index af3f7f194c74..884c4579df66 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -7,6 +7,7 @@ _T = TypeVar("_T") _Context = TypeVar("_Context") _TransitionResult: TypeAlias = tuple[_Context, str | None, list[str]] _TransitionMethod: TypeAlias = Callable[[Match[str], _Context, str], _TransitionResult[_Context]] +_Observer: TypeAlias = Callable[[StateMachine[_Context]], None] class StateMachine(Generic[_Context]): input_lines: StringList | None @@ -17,7 +18,7 @@ class StateMachine(Generic[_Context]): initial_state: str current_state: str states: dict[str, State[_Context]] - observers: list[Callable[[Self], None]] + observers: list[_Observer[_Context]] def __init__(self, state_classes: Iterable[type[State[_Context]]], initial_state: str, debug: bool = False) -> None: ... def unlink(self) -> None: ... def run( @@ -48,8 +49,8 @@ class StateMachine(Generic[_Context]): def add_states(self, state_classes: Iterable[type[State[_Context]]]) -> None: ... def runtime_init(self) -> None: ... def error(self) -> None: ... - def attach_observer(self, observer) -> None: ... - def detach_observer(self, observer) -> None: ... + def attach_observer(self, observer: _Observer[_Context]) -> None: ... + def detach_observer(self, observer: _Observer[_Context]) -> None: ... def notify_observers(self) -> None: ... class State(Generic[_Context]): From 7e176d08f91ca6675a4a6e6a28ed06ed27a23f0e Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:32:23 +0000 Subject: [PATCH 22/26] use 'Self' in ViewList class --- stubs/docutils/docutils/statemachine.pyi | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 884c4579df66..62b0918fdb7b 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,6 +1,6 @@ from collections.abc import Callable, Generator, Iterable, Iterator, Sequence from re import Match, Pattern -from typing import Any, ClassVar, Generic, SupportsIndex, TypeVar, overload +from typing import Any, ClassVar, Generic, SupportsIndex, TypeVar, overload, Self from typing_extensions import Self, TypeAlias _T = TypeVar("_T") @@ -114,14 +114,14 @@ class SearchStateMachineWS(_SearchOverride, StateMachineWS[_Context]): ... class ViewList(Generic[_T]): data: list[_T] items: list[tuple[str, int]] - parent: ViewList[_T] + parent: Self parent_offset: int def __init__( self, - initlist: ViewList[_T] | Sequence[_T] | None = None, + initlist: Self | Sequence[_T] | None = None, source: str | None = None, items: list[tuple[str, int]] | None = None, - parent: ViewList[_T] | None = None, + parent: Self | None = None, parent_offset: int | None = None, ) -> None: ... def __lt__(self, other: Any) -> bool: ... @@ -130,24 +130,24 @@ class ViewList(Generic[_T]): def __ne__(self, other: object) -> bool: ... def __gt__(self, other: Any) -> bool: ... def __ge__(self, other: Any) -> bool: ... - def __contains__(self, item: ViewList[_T]) -> bool: ... + def __contains__(self, item: Self) -> bool: ... def __len__(self) -> int: ... @overload - def __getitem__(self, i: slice) -> ViewList[_T]: ... + def __getitem__(self, i: slice) -> Self: ... @overload def __getitem__(self, i: SupportsIndex) -> _T: ... @overload - def __setitem__(self, i: slice, item: ViewList[_T]) -> None: ... + def __setitem__(self, i: slice, item: Self) -> None: ... @overload def __setitem__(self, i: SupportsIndex, item: _T) -> None: ... def __delitem__(self, i: SupportsIndex) -> None: ... - def __add__(self, other: ViewList[_T]) -> Self: ... - def __radd__(self, other: ViewList[_T]) -> Self: ... - def __iadd__(self, other: ViewList[_T]) -> Self: ... + def __add__(self, other: Self) -> Self: ... + def __radd__(self, other: Self) -> Self: ... + def __iadd__(self, other: Self) -> Self: ... def __mul__(self, n: int) -> Self: ... __rmul__ = __mul__ def __imul__(self, n: int) -> Self: ... - def extend(self, other: ViewList[_T]) -> None: ... + def extend(self, other: Self) -> None: ... def append(self, item: _T, source: str | None = None, offset: int = 0) -> None: ... def insert(self, i: int, item: _T, source: str | None = None, offset: int = 0) -> None: ... def pop(self, i: int = -1) -> _T: ... From b8897e92ccfc03885b8b6d1cfa0ea3929c798bf9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:33:56 +0000 Subject: [PATCH 23/26] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/docutils/docutils/statemachine.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 62b0918fdb7b..9db1b865c6c5 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable, Generator, Iterable, Iterator, Sequence from re import Match, Pattern -from typing import Any, ClassVar, Generic, SupportsIndex, TypeVar, overload, Self -from typing_extensions import Self, TypeAlias +from typing import Any, ClassVar, Generic, Self, SupportsIndex, TypeVar, overload +from typing_extensions import TypeAlias _T = TypeVar("_T") _Context = TypeVar("_Context") From b7bde108fbbe4ae7173cc79a17e58c8244184312 Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Wed, 13 Mar 2024 14:26:50 +0000 Subject: [PATCH 24/26] fixup --- stubs/docutils/@tests/stubtest_allowlist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/docutils/@tests/stubtest_allowlist.txt b/stubs/docutils/@tests/stubtest_allowlist.txt index 78233e17e0f8..75de2ad813fa 100644 --- a/stubs/docutils/@tests/stubtest_allowlist.txt +++ b/stubs/docutils/@tests/stubtest_allowlist.txt @@ -10,6 +10,7 @@ docutils.nodes.GenericNodeVisitor.__getattr__ # these methods take a rawsource parameter that has been deprecated and is completely ignored, so we omit it from the stub docutils.nodes.Text.__new__ docutils.parsers.recommonmark_wrapper +docutils.parsers.rst.directives.misc.MetaBody.__getattr__ docutils.statemachine.State.nested_sm # is initialised in __init__ docutils.statemachine.State.nested_sm_kwargs # is initialised in __init__ docutils.statemachine.ViewList.__iter__ # doesn't exist at runtime, but the class is iterable due to __getitem__ From 307770aef2f04cf994e06bfaee71cc6548a8e759 Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Wed, 13 Mar 2024 14:32:37 +0000 Subject: [PATCH 25/26] fixup --- stubs/docutils/docutils/statemachine.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index 9db1b865c6c5..f06ee281f890 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable, Generator, Iterable, Iterator, Sequence from re import Match, Pattern -from typing import Any, ClassVar, Generic, Self, SupportsIndex, TypeVar, overload -from typing_extensions import TypeAlias +from typing import Any, ClassVar, Generic, SupportsIndex, TypeVar, overload +from typing_extensions import Self, TypeAlias _T = TypeVar("_T") _Context = TypeVar("_Context") From de82d67d95b068377295a2ffaf80278da9533856 Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:26:39 +0000 Subject: [PATCH 26/26] Update statemachine.pyi --- stubs/docutils/docutils/statemachine.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/docutils/docutils/statemachine.pyi b/stubs/docutils/docutils/statemachine.pyi index f06ee281f890..162eedb7d502 100644 --- a/stubs/docutils/docutils/statemachine.pyi +++ b/stubs/docutils/docutils/statemachine.pyi @@ -130,7 +130,7 @@ class ViewList(Generic[_T]): def __ne__(self, other: object) -> bool: ... def __gt__(self, other: Any) -> bool: ... def __ge__(self, other: Any) -> bool: ... - def __contains__(self, item: Self) -> bool: ... + def __contains__(self, item: _T) -> bool: ... def __len__(self) -> int: ... @overload def __getitem__(self, i: slice) -> Self: ...