Skip to content

Commit d2e9724

Browse files
committed
chore: linter run
1 parent 4e82d39 commit d2e9724

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

python/twinleaf/__init__.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,17 @@ def _interact(self):
199199

200200
type _rpc_type = int | float | str | bytes | None
201201

202+
202203
def _is_capture_rpc(pyrpc: _twinleaf._Rpc) -> bool:
203-
meta_raw = getattr(pyrpc, 'meta_raw', 0)
204+
meta_raw = getattr(pyrpc, "meta_raw", 0)
204205
return (
205-
getattr(pyrpc, 'is_capture', False)
206-
or pyrpc.type_str == 'capture'
206+
getattr(pyrpc, "is_capture", False)
207+
or pyrpc.type_str == "capture"
207208
or (meta_raw & 0x1000) != 0
208-
or pyrpc.name.rsplit('.', 1)[-1] == 'capture'
209+
or pyrpc.name.rsplit(".", 1)[-1] == "capture"
209210
)
210211

212+
211213
class _RpcNode:
212214
"""Base class for RPCs and surveys in the device tree"""
213215

@@ -249,8 +251,8 @@ def __new__(cls, pyrpc: _twinleaf._Rpc, device: Device):
249251
match pyrpc:
250252
case r if _is_capture_rpc(r):
251253
subclass = _RpcCapture
252-
case r if r.type_str == '' and r.size_bytes != 0:
253-
subclass = _RpcReadWrite # unknown/bytes rpc
254+
case r if r.type_str == "" and r.size_bytes != 0:
255+
subclass = _RpcReadWrite # unknown/bytes rpc
254256
case r if r.readable and r.writable:
255257
subclass = _RpcReadWrite
256258
case r if r.writable:
@@ -265,16 +267,16 @@ def __new__(cls, pyrpc: _twinleaf._Rpc, device: Device):
265267
def __init__(self, pyrpc: _twinleaf._Rpc, device: Device):
266268
super().__init__(pyrpc.name)
267269
self._device = device
268-
self._meta_raw = getattr(pyrpc, 'meta_raw', 0)
270+
self._meta_raw = getattr(pyrpc, "meta_raw", 0)
269271
self._data_size = pyrpc.size_bytes
270272
self._readable = pyrpc.readable
271273
self._writable = pyrpc.writable
272274
self._type: type | None = None
273275
self._is_capture = _is_capture_rpc(pyrpc)
274276
match pyrpc.type_str:
275-
case 'capture':
277+
case "capture":
276278
self._data_type = None
277-
case t if t.startswith('u'):
279+
case t if t.startswith("u"):
278280
self._type = int
279281
self._data_type = 0
280282
self._signed = False
@@ -298,16 +300,16 @@ def __init__(self, pyrpc: _twinleaf._Rpc, device: Device):
298300
def __repr__(self):
299301
if self._is_capture:
300302
return f"{self.__module__}.{self.__class__.__name__}('{self.__name__}', capture=True)"
301-
ret = super().__repr__().strip(')') + ", "
302-
if hasattr(self, '_signed') and not self._signed:
303+
ret = super().__repr__().strip(")") + ", "
304+
if hasattr(self, "_signed") and not self._signed:
303305
ret += "u"
304306
ret += self._type.__name__ if self._type is not None else "none"
305307
if self._data_size: # is not 0 or None
306308
ret += str(self._data_size * 8)
307309
ret += ")"
308310
return ret
309311

310-
def _call(self, arg: _rpc_type=None, *, raw: bool=False) -> _rpc_type:
312+
def _call(self, arg: _rpc_type = None, *, raw: bool = False) -> _rpc_type:
311313
if self._is_capture:
312314
if arg is None:
313315
return self._device._capture(self.__name__, 5.0, raw)
@@ -349,11 +351,13 @@ def _call(self, arg: _rpc_type=None, *, raw: bool=False) -> _rpc_type:
349351

350352

351353
class _RpcReadOnly(_Rpc):
352-
def __call__(self, timeout: float | None = None, *, raw: bool=False):
354+
def __call__(self, timeout: float | None = None, *, raw: bool = False):
353355
if self._is_capture:
354356
return self._call(timeout, raw=raw)
355357
if timeout is not None or raw:
356-
raise TypeError(f"{self.__name__} is read-only and does not accept an argument")
358+
raise TypeError(
359+
f"{self.__name__} is read-only and does not accept an argument"
360+
)
357361
return self._call()
358362

359363

@@ -376,9 +380,10 @@ class _RpcCapture(_Rpc):
376380
def __repr__(self):
377381
return f"{self.__module__}.{self.__class__.__name__}('{self.__name__}', capture=True)"
378382

379-
def __call__(self, timeout: float = 5.0, *, raw: bool=False) -> dict:
383+
def __call__(self, timeout: float = 5.0, *, raw: bool = False) -> dict:
380384
return self._device._capture(self.__name__, timeout, raw)
381385

386+
382387
# Samples classes
383388
class _SamplesBase:
384389
"""Base class for sample objects"""

python/twinleaf/_twinleaf.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class _Device:
4040
def _rpc(self, name: str, req: bytes) -> bytes: ...
4141
def _rpc_list(self) -> list[Any]: ...
4242
def _rpc_registry(self) -> _RpcRegistry: ...
43+
def _capture(
44+
self,
45+
name: str,
46+
timeout_seconds: float,
47+
raw: bool,
48+
) -> Any: ...
4349
def _samples(
4450
self,
4551
n: int | None = ...,

0 commit comments

Comments
 (0)