11from collections .abc import Callable , Generator , Iterator , Sequence
22from re import Match , Pattern
33from typing import Any , Generic , TypeVar , overload
4- from typing_extensions import Self , TypeAlias
4+ from typing_extensions import Self
55
66__docformat__ : str
77
88_Context = TypeVar ("_Context" )
9- _TransitionResult : TypeAlias = tuple [_Context , str | None , list [str ]]
10- _TransitionMethod : TypeAlias = Callable [[Match [str ], _Context , str ], _TransitionResult [_Context ]]
119
1210class StateMachine (Generic [_Context ]):
1311 input_lines : StringList | None
@@ -44,7 +42,7 @@ class StateMachine(Generic[_Context]):
4442 def get_text_block (self , flush_left : bool = False ) -> StringList : ...
4543 def check_line (
4644 self , context : _Context , state : State [_Context ], transitions : list [str ] | None = ...
47- ) -> _TransitionResult [_Context ]: ...
45+ ) -> tuple [_Context , str | None , list [ str ] ]: ...
4846 def add_state (self , state_class : type [State [_Context ]]) -> None : ...
4947 def add_states (self , state_classes : Sequence [type [State [_Context ]]]) -> None : ...
5048 def runtime_init (self ) -> None : ...
@@ -71,16 +69,24 @@ class State(Generic[_Context]):
7169 def remove_transition (self , name : str ) -> None : ...
7270 def make_transition (
7371 self , name : str , next_state : str | None = None
74- ) -> tuple [Pattern [str ], _TransitionMethod [ _Context ], str ]: ...
72+ ) -> tuple [Pattern [str ], Callable [[ Match [ str ], _Context , str ], tuple [ _Context , str | None , list [ str ]] ], str ]: ...
7573 def make_transitions (
7674 self , name_list : list [str | tuple [str ] | tuple [str , str ]]
77- ) -> tuple [list [str ], dict [str , tuple [Pattern [str ], _TransitionMethod [_Context ], str ]]]: ...
75+ ) -> tuple [
76+ list [str ],
77+ dict [str , tuple [Pattern [str ], Callable [[Match [str ], _Context , str ], tuple [_Context , str | None , list [str ]]], str ]],
78+ ]: ...
7879 def no_match (
79- self , context : Any , transitions : tuple [list [str ], dict [str , tuple [Pattern [str ], _TransitionMethod [_Context ], str ]]]
80- ) -> _TransitionResult [_Context ]: ...
80+ self ,
81+ context : Any ,
82+ transitions : tuple [
83+ list [str ],
84+ dict [str , tuple [Pattern [str ], Callable [[Match [str ], _Context , str ], tuple [_Context , str | None , list [str ]]], str ]],
85+ ],
86+ ) -> tuple [_Context , str | None , list [str ]]: ...
8187 def bof (self , context : _Context ) -> tuple [_Context , list [str ]]: ...
8288 def eof (self , context : _Context ) -> list [str ]: ...
83- def nop (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
89+ def nop (self , match : Match [str ], context : _Context , next_state : str ) -> tuple [_Context , str | None , list [ str ] ]: ...
8490
8591class StateMachineWS (StateMachine [_Context ]):
8692 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]):
100106 ws_initial_transitions : Sequence [str ]
101107 def __init__ (self , state_machine : StateMachine [_Context ], debug : bool = False ) -> None : ...
102108 def add_initial_transitions (self ) -> None : ...
103- def blank (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
104- def indent (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
105- def known_indent (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
106- def first_known_indent (self , match : Match [str ], context : _Context , next_state : str ) -> _TransitionResult [_Context ]: ...
109+ def blank (self , match : Match [str ], context : _Context , next_state : str ) -> tuple [_Context , str | None , list [str ]]: ...
110+ def indent (self , match : Match [str ], context : _Context , next_state : str ) -> tuple [_Context , str | None , list [str ]]: ...
111+ def known_indent (self , match : Match [str ], context : _Context , next_state : str ) -> tuple [_Context , str | None , list [str ]]: ...
112+ def first_known_indent (
113+ self , match : Match [str ], context : _Context , next_state : str
114+ ) -> tuple [_Context , str | None , list [str ]]: ...
107115
108116class _SearchOverride :
109117 def match (self , pattern : Pattern [str ]) -> Match [str ]: ...
0 commit comments