66import  logging 
77import  threading 
88from  abc  import  ABC , abstractmethod 
9- from  collections .abc  import  Iterator , Sequence 
9+ from  collections .abc  import  Callable ,  Iterator , Sequence 
1010from  enum  import  Enum , auto 
1111from  time  import  time 
1212from  types  import  TracebackType 
1313from  typing  import  (
14-     Callable ,
15-     Optional ,
16-     Union ,
1714    cast ,
1815)
1916
@@ -68,7 +65,7 @@ class BusABC(ABC):
6865    def  __init__ (
6966        self ,
7067        channel : can .typechecking .Channel ,
71-         can_filters : Optional [ can .typechecking .CanFilters ]  =  None ,
68+         can_filters : can .typechecking .CanFilters   |   None  =  None ,
7269        ** kwargs : object ,
7370    ):
7471        """Construct and open a CAN bus instance of the specified type. 
@@ -101,7 +98,7 @@ def __init__(
10198    def  __str__ (self ) ->  str :
10299        return  self .channel_info 
103100
104-     def  recv (self , timeout : Optional [ float ]  =  None ) ->  Optional [ Message ] :
101+     def  recv (self , timeout : float   |   None   =  None ) ->  Message   |   None :
105102        """Block waiting for a message from the Bus. 
106103
107104        :param timeout: 
@@ -139,9 +136,7 @@ def recv(self, timeout: Optional[float] = None) -> Optional[Message]:
139136
140137                return  None 
141138
142-     def  _recv_internal (
143-         self , timeout : Optional [float ]
144-     ) ->  tuple [Optional [Message ], bool ]:
139+     def  _recv_internal (self , timeout : float  |  None ) ->  tuple [Message  |  None , bool ]:
145140        """ 
146141        Read a message from the bus and tell whether it was filtered. 
147142        This methods may be called by :meth:`~can.BusABC.recv` 
@@ -184,7 +179,7 @@ def _recv_internal(
184179        raise  NotImplementedError ("Trying to read from a write only bus?" )
185180
186181    @abstractmethod  
187-     def  send (self , msg : Message , timeout : Optional [ float ]  =  None ) ->  None :
182+     def  send (self , msg : Message , timeout : float   |   None  =  None ) ->  None :
188183        """Transmit a message to the CAN bus. 
189184
190185        Override this method to enable the transmit path. 
@@ -205,12 +200,12 @@ def send(self, msg: Message, timeout: Optional[float] = None) -> None:
205200
206201    def  send_periodic (
207202        self ,
208-         msgs : Union [ Message ,  Sequence [Message ] ],
203+         msgs : Message   |   Sequence [Message ],
209204        period : float ,
210-         duration : Optional [ float ]  =  None ,
205+         duration : float   |   None  =  None ,
211206        store_task : bool  =  True ,
212207        autostart : bool  =  True ,
213-         modifier_callback : Optional [ Callable [[Message ], None ]]  =  None ,
208+         modifier_callback : Callable [[Message ], None ]  |   None  =  None ,
214209    ) ->  can .broadcastmanager .CyclicSendTaskABC :
215210        """Start sending messages at a given period on this bus. 
216211
@@ -297,11 +292,11 @@ def wrapped_stop_method(remove_task: bool = True) -> None:
297292
298293    def  _send_periodic_internal (
299294        self ,
300-         msgs : Union [ Sequence [Message ],  Message ] ,
295+         msgs : Sequence [Message ]  |   Message ,
301296        period : float ,
302-         duration : Optional [ float ]  =  None ,
297+         duration : float   |   None  =  None ,
303298        autostart : bool  =  True ,
304-         modifier_callback : Optional [ Callable [[Message ], None ]]  =  None ,
299+         modifier_callback : Callable [[Message ], None ]  |   None  =  None ,
305300    ) ->  can .broadcastmanager .CyclicSendTaskABC :
306301        """Default implementation of periodic message sending using threading. 
307302
@@ -378,20 +373,18 @@ def __iter__(self) -> Iterator[Message]:
378373                yield  msg 
379374
380375    @property  
381-     def  filters (self ) ->  Optional [ can .typechecking .CanFilters ] :
376+     def  filters (self ) ->  can .typechecking .CanFilters   |   None :
382377        """ 
383378        Modify the filters of this bus. See :meth:`~can.BusABC.set_filters` 
384379        for details. 
385380        """ 
386381        return  self ._filters 
387382
388383    @filters .setter  
389-     def  filters (self , filters : Optional [ can .typechecking .CanFilters ] ) ->  None :
384+     def  filters (self , filters : can .typechecking .CanFilters   |   None ) ->  None :
390385        self .set_filters (filters )
391386
392-     def  set_filters (
393-         self , filters : Optional [can .typechecking .CanFilters ] =  None 
394-     ) ->  None :
387+     def  set_filters (self , filters : can .typechecking .CanFilters  |  None  =  None ) ->  None :
395388        """Apply filtering to all messages received by this Bus. 
396389
397390        All messages that match at least one filter are returned. 
@@ -417,7 +410,7 @@ def set_filters(
417410        with  contextlib .suppress (NotImplementedError ):
418411            self ._apply_filters (self ._filters )
419412
420-     def  _apply_filters (self , filters : Optional [ can .typechecking .CanFilters ] ) ->  None :
413+     def  _apply_filters (self , filters : can .typechecking .CanFilters   |   None ) ->  None :
421414        """ 
422415        Hook for applying the filters to the underlying kernel or 
423416        hardware if supported/implemented by the interface. 
@@ -484,9 +477,9 @@ def __enter__(self) -> Self:
484477
485478    def  __exit__ (
486479        self ,
487-         exc_type : Optional [ type [BaseException ]] ,
488-         exc_value : Optional [ BaseException ] ,
489-         traceback : Optional [ TracebackType ] ,
480+         exc_type : type [BaseException ]  |   None ,
481+         exc_value : BaseException   |   None ,
482+         traceback : TracebackType   |   None ,
490483    ) ->  None :
491484        self .shutdown ()
492485
0 commit comments