44
55import logging
66from itertools import chain # , zip_longest
7- from typing import (
8- TYPE_CHECKING ,
9- Any ,
10- Dict ,
11- Generator ,
12- List ,
13- Optional ,
14- Tuple ,
15- Union ,
16- cast ,
17- )
7+ from typing import TYPE_CHECKING , Any , Generator , Optional , Union , cast
188
199from superstate .exception import (
2010 InvalidConfig ,
3929#
4030# initial: Optional[Initial]
4131# kind: Optional[str]
42- # states: List [State]
43- # transitions: List [State]
32+ # states: list [State]
33+ # transitions: list [State]
4434# on_entry: Optional[ActionTypes]
4535# on_exit: Optional[ActionTypes]
4636#
4737# def __new__(
4838# cls,
4939# name: str,
50- # bases: Tuple [type, ...],
51- # attrs: Dict [str, Any],
40+ # bases: tuple [type, ...],
41+ # attrs: dict [str, Any],
5242# ) -> 'MetaState':
5343# initial = attrs.pop('initial', None)
5444# kind = attrs.pop('type', None)
7060class TransitionMixin :
7161 """Provide an atomic state for a statechart."""
7262
73- __transitions : List [Transition ]
63+ __transitions : list [Transition ]
7464
7565 @property
76- def transitions (self ) -> Tuple [Transition , ...]:
66+ def transitions (self ) -> tuple [Transition , ...]:
7767 """Return transitions of this state."""
7868 return tuple (self .__transitions )
7969
8070 @transitions .setter
81- def transitions (self , transitions : List [Transition ]) -> None :
71+ def transitions (self , transitions : list [Transition ]) -> None :
8272 """Initialize atomic state."""
8373 self .__transitions = transitions
8474
8575 def add_transition (self , transition : Transition ) -> None :
8676 """Add transition to this state."""
8777 self .__transitions .append (transition )
8878
89- def get_transition (self , event : str ) -> Tuple [Transition , ...]:
79+ def get_transition (self , event : str ) -> tuple [Transition , ...]:
9080 """Get each transition maching event."""
9181 return tuple (
9282 filter (
@@ -161,15 +151,15 @@ class State:
161151 # '__type',
162152 # ]
163153
164- __stack : List [State ]
154+ __stack : list [State ]
165155 datamodel : DataModel
166156 name : str = cast (str , Identifier ())
167157 # history: Optional['HistoryState']
168158 # final: Optional[FinalState]
169- # states: Dict [str, State]
170- # transitions: Tuple [Transition, ...]
171- # onentry: Tuple [ActionTypes, ...]
172- # onexit: Tuple [ActionTypes, ...]
159+ states : dict [str , State ]
160+ # transitions: tuple [Transition, ...]
161+ # onentry: tuple [ActionTypes, ...]
162+ # onexit: tuple [ActionTypes, ...]
173163
174164 # pylint: disable-next=unused-argument
175165 def __new__ (cls , * args : Any , ** kwargs : Any ) -> State :
@@ -193,7 +183,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> State:
193183 def __init__ (
194184 self , # pylint: disable=unused-argument
195185 name : str ,
196- # settings: Optional[Dict [str, Any]] = None,
186+ # settings: Optional[dict [str, Any]] = None,
197187 # /,
198188 ** kwargs : Any ,
199189 ) -> None :
@@ -488,7 +478,7 @@ def run_on_entry(self, ctx: StateChart) -> Optional[Any]:
488478class SubstateMixin (State ):
489479 """Provide composite abstract to define nested state types."""
490480
491- __states : Dict [str , State ] = {}
481+ __states : dict [str , State ] = {}
492482
493483 def __getattr__ (self , name : str ) -> Any :
494484 if name .startswith ('__' ):
@@ -499,12 +489,12 @@ def __getattr__(self, name: str) -> Any:
499489 raise AttributeError
500490
501491 @property
502- def states (self ) -> Dict [str , State ]:
492+ def states (self ) -> dict [str , State ]:
503493 """Return states."""
504494 return self .__states
505495
506496 @states .setter
507- def states (self , states : List [State ]) -> None :
497+ def states (self , states : list [State ]) -> None :
508498 """Define states."""
509499 if not self .__states :
510500 self .__states = {}
@@ -529,7 +519,7 @@ def get_state(self, name: str) -> Optional[State]:
529519# class SubstateMixin(State):
530520# """Provide composite abstract to define nested state types."""
531521#
532- # __states: List [State] = []
522+ # __states: list [State] = []
533523#
534524# def __getattr__(self, name: str) -> Any:
535525# if name.startswith('__'):
@@ -540,12 +530,12 @@ def get_state(self, name: str) -> Optional[State]:
540530# raise AttributeError
541531#
542532# @property
543- # def states(self) -> List [State]:
533+ # def states(self) -> list [State]:
544534# """Return states."""
545535# return self.__states
546536#
547537# @states.setter
548- # def states(self, states: List [State]) -> None:
538+ # def states(self, states: list [State]) -> None:
549539# """Define states."""
550540# if not self.__states:
551541# for state in states:
@@ -580,7 +570,7 @@ def __init__(self, name: str, **kwargs: Any) -> None:
580570 self .states = kwargs .pop ('states' , [])
581571 super ().__init__ (name , ** kwargs )
582572
583- def run_on_entry (self , ctx : StateChart ) -> Optional [Tuple [Any , ...]]:
573+ def run_on_entry (self , ctx : StateChart ) -> Optional [tuple [Any , ...]]:
584574 # if next(
585575 # (x for x in self.states if isinstance(x, HistoryState)), False
586576 # ):
@@ -596,7 +586,7 @@ def run_on_entry(self, ctx: StateChart) -> Optional[Tuple[Any, ...]]:
596586 )
597587 if initial and ctx .current_state != initial :
598588 ctx .change_state (initial )
599- results : List [Any ] = []
589+ results : list [Any ] = []
600590 results += filter (None , [super ().run_on_entry (ctx )])
601591 # XXX: self transitions should still be possible here
602592 if (
0 commit comments