44
55import logging
66import time
7+ from collections .abc import Sequence
78from typing import Any , Optional , Union
89from unittest .mock import Mock
910
1415 CanInterfaceNotImplementedError ,
1516 error_check ,
1617)
18+ from ..typechecking import AutoDetectedConfig
1719from ..util import check_or_adjust_timing_clock , deprecated_args_alias
1820
1921logger = logging .getLogger (__name__ )
@@ -31,7 +33,7 @@ class CantactBus(BusABC):
3133 """CANtact interface"""
3234
3335 @staticmethod
34- def _detect_available_configs ():
36+ def _detect_available_configs () -> Sequence [ AutoDetectedConfig ] :
3537 try :
3638 interface = cantact .Interface ()
3739 except (NameError , SystemError , AttributeError ):
@@ -40,7 +42,7 @@ def _detect_available_configs():
4042 )
4143 return []
4244
43- channels = []
45+ channels : list [ AutoDetectedConfig ] = []
4446 for i in range (0 , interface .channel_count ()):
4547 channels .append ({"interface" : "cantact" , "channel" : f"ch:{ i } " })
4648 return channels
@@ -121,7 +123,14 @@ def __init__(
121123 ** kwargs ,
122124 )
123125
124- def _recv_internal (self , timeout ):
126+ def _recv_internal (
127+ self , timeout : Optional [float ]
128+ ) -> tuple [Optional [Message ], bool ]:
129+ if timeout is None :
130+ raise TypeError (
131+ f"{ self .__class__ .__name__ } expects a numeric `timeout` value."
132+ )
133+
125134 with error_check ("Cannot receive message" ):
126135 frame = self .interface .recv (int (timeout * 1000 ))
127136 if frame is None :
@@ -140,7 +149,7 @@ def _recv_internal(self, timeout):
140149 )
141150 return msg , False
142151
143- def send (self , msg , timeout = None ):
152+ def send (self , msg : Message , timeout : Optional [ float ] = None ) -> None :
144153 with error_check ("Cannot send message" ):
145154 self .interface .send (
146155 self .channel ,
@@ -151,13 +160,13 @@ def send(self, msg, timeout=None):
151160 msg .data ,
152161 )
153162
154- def shutdown (self ):
163+ def shutdown (self ) -> None :
155164 super ().shutdown ()
156165 with error_check ("Cannot shutdown interface" ):
157166 self .interface .stop ()
158167
159168
160- def mock_recv (timeout ) :
169+ def mock_recv (timeout : int ) -> Optional [ dict [ str , Any ]] :
161170 if timeout > 0 :
162171 return {
163172 "id" : 0x123 ,
0 commit comments