11from collections .abc import Callable , Generator , Iterator , Sequence
22from re import Match , Pattern
3- from typing import Any , Generic , TypeVar , overload
3+ from typing import Any , Generic , TypeAlias , TypeVar , overload
44from typing_extensions import Self
55
66_Context = TypeVar ("_Context" )
7+ _TransitionResult : TypeAlias = tuple [_Context , str | None , list [str ]]
8+ _TransitionMethod : TypeAlias = Callable [[Match [str ], _Context , str ], _TransitionResult [_Context ]]
79
810class StateMachine (Generic [_Context ]):
911 input_lines : StringList | None
@@ -40,7 +42,7 @@ class StateMachine(Generic[_Context]):
4042 def get_text_block (self , flush_left : bool = False ) -> StringList : ...
4143 def check_line (
4244 self , context : _Context , state : State [_Context ], transitions : list [str ] | None = ...
43- ) -> tuple [_Context , str | None , list [ str ] ]: ...
45+ ) -> _TransitionResult [_Context ]: ...
4446 def add_state (self , state_class : type [State [_Context ]]) -> None : ...
4547 def add_states (self , state_classes : Sequence [type [State [_Context ]]]) -> None : ...
4648 def runtime_init (self ) -> None : ...
@@ -67,24 +69,16 @@ class State(Generic[_Context]):
6769 def remove_transition (self , name : str ) -> None : ...
6870 def make_transition (
6971 self , name : str , next_state : str | None = None
70- ) -> tuple [Pattern [str ], Callable [[ Match [ str ], _Context , str ], tuple [ _Context , str | None , list [ str ]] ], str ]: ...
72+ ) -> tuple [Pattern [str ], _TransitionMethod [ _Context ], str ]: ...
7173 def make_transitions (
7274 self , name_list : list [str | tuple [str ] | tuple [str , str ]]
73- ) -> tuple [
74- list [str ],
75- dict [str , tuple [Pattern [str ], Callable [[Match [str ], _Context , str ], tuple [_Context , str | None , list [str ]]], str ]],
76- ]: ...
75+ ) -> tuple [list [str ], dict [str , tuple [Pattern [str ], _TransitionMethod [_Context ], str ]]]: ...
7776 def no_match (
78- self ,
79- context : Any ,
80- transitions : tuple [
81- list [str ],
82- dict [str , tuple [Pattern [str ], Callable [[Match [str ], _Context , str ], tuple [_Context , str | None , list [str ]]], str ]],
83- ],
84- ) -> tuple [_Context , str | None , list [str ]]: ...
77+ self , context : Any , transitions : tuple [list [str ], dict [str , tuple [Pattern [str ], _TransitionMethod [_Context ], str ]]]
78+ ) -> _TransitionResult [_Context ]: ...
8579 def bof (self , context : _Context ) -> tuple [_Context , list [str ]]: ...
8680 def eof (self , context : _Context ) -> list [str ]: ...
87- def nop (self , match : Match [str ], context : _Context , next_state : str ) -> tuple [_Context , str | None , list [ str ] ]: ...
81+ def nop (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
8882
8983class StateMachineWS (StateMachine [_Context ]):
9084 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]):
10498 ws_initial_transitions : Sequence [str ]
10599 def __init__ (self , state_machine : StateMachine [_Context ], debug : bool = False ) -> None : ...
106100 def add_initial_transitions (self ) -> None : ...
107- def blank (self , match : Match [str ], context : _Context , next_state : str ) -> tuple [_Context , str | None , list [str ]]: ...
108- def indent (self , match : Match [str ], context : _Context , next_state : str ) -> tuple [_Context , str | None , list [str ]]: ...
109- def known_indent (self , match : Match [str ], context : _Context , next_state : str ) -> tuple [_Context , str | None , list [str ]]: ...
110- def first_known_indent (
111- self , match : Match [str ], context : _Context , next_state : str
112- ) -> tuple [_Context , str | None , list [str ]]: ...
101+ def blank (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
102+ def indent (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
103+ def known_indent (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
104+ def first_known_indent (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
113105
114106class _SearchOverride :
115107 def match (self , pattern : Pattern [str ]) -> Match [str ]: ...
0 commit comments