Skip to content

Commit d387252

Browse files
committed
chore: make pyright a little happier with type handling
1 parent 13139c1 commit d387252

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

python/twinleaf/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from twinleaf import _twinleaf
1+
from twinleaf import _twinleaf # type: ignore[attr-defined]
22

33
class Device(_twinleaf._Device):
44
""" Primary TIO interface with sensor object """
@@ -31,6 +31,7 @@ def _rpc_int(self, name: str, size: int, signed: bool, value: int | None = None)
3131
case 2, False: fstr = '<H'
3232
case 4, False: fstr = '<I'
3333
case 8, False: fstr = '<Q'
34+
case _: raise ValueError(f"Unsupported int size/signed combo: {size}, {signed}")
3435
payload = b'' if value is None else struct.pack(fstr, value)
3536
rep = self._rpc(name, payload)
3637
val = struct.unpack(fstr, rep)[0]
@@ -197,7 +198,7 @@ def __new__(cls, pyrpc: _twinleaf._Rpc, device: Device):
197198
subclass = _RpcReadOnly
198199
case _:
199200
subclass = _RpcAction
200-
rpc = super().__new__(subclass)
201+
rpc = super().__new__(subclass) # type: ignore[arg-type]
201202
return rpc
202203

203204
def __init__(self, pyrpc: _twinleaf._Rpc, device: Device):
@@ -242,11 +243,14 @@ def __repr__(self):
242243
def _call(self, arg: _rpc_type=None) -> _rpc_type:
243244
match self._type:
244245
case t if t is int:
246+
assert arg is None or isinstance(arg, int)
245247
return self._device._rpc_int(self.__name__, self._data_size, self._signed, arg)
246248
case t if t is float:
249+
assert arg is None or isinstance(arg, float)
247250
return self._device._rpc_float(self.__name__, self._data_size, arg)
248251
case t if t is str:
249252
if arg is None: arg = ''
253+
assert isinstance(arg, str)
250254
return self._device._rpc(self.__name__, arg.encode()).decode()
251255
case t if t is bytes:
252256
if arg is None: arg = b''

0 commit comments

Comments
 (0)