Same mypy checks as openpilot (#1233)

* no specific revision for mypy

* bump to ~OP version

* same warnings as openpilot

* ignore

* fix

* rm that

* switch to ignore so mypy lets us know when it's fixed

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
Shane Smiskol 2023-02-11 12:25:13 -08:00 committed by GitHub
parent d15250cb14
commit 17450b277d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 22 deletions

11
mypy.ini Normal file
View File

@ -0,0 +1,11 @@
[mypy]
; third-party packages
ignore_missing_imports = True
; helpful warnings
warn_redundant_casts = True
warn_unreachable = True
warn_unused_ignores = True
; restrict dynamic typing
warn_return_any = True

View File

@ -100,9 +100,9 @@ class CcpClient():
msgs = self._panda.can_recv() or [] msgs = self._panda.can_recv() or []
if len(msgs) >= 256: if len(msgs) >= 256:
print("CAN RX buffer overflow!!!", file=sys.stderr) print("CAN RX buffer overflow!!!", file=sys.stderr)
for rx_addr, _, rx_data, rx_bus in msgs: for rx_addr, _, rx_data_bytearray, rx_bus in msgs:
if rx_bus == self.can_bus and rx_addr == self.rx_addr: if rx_bus == self.can_bus and rx_addr == self.rx_addr:
rx_data = bytes(rx_data) # convert bytearray to bytes rx_data = bytes(rx_data_bytearray)
if self.debug: if self.debug:
print(f"CAN-RX: {hex(rx_addr)} - 0x{bytes.hex(rx_data)}") print(f"CAN-RX: {hex(rx_addr)} - 0x{bytes.hex(rx_data)}")
assert len(rx_data) == 8, f"message length not 8: {len(rx_data)}" assert len(rx_data) == 8, f"message length not 8: {len(rx_data)}"
@ -183,7 +183,7 @@ class CcpClient():
resp = self._recv_dto(0.025) resp = self._recv_dto(0.025)
# mta_addr_ext = resp[0] # mta_addr_ext = resp[0]
mta_addr = struct.unpack(f"{self.byte_order.value}I", resp[1:5])[0] mta_addr = struct.unpack(f"{self.byte_order.value}I", resp[1:5])[0]
return mta_addr return mta_addr # type: ignore
def download_6_bytes(self, data: bytes) -> int: def download_6_bytes(self, data: bytes) -> int:
if len(data) != 6: if len(data) != 6:
@ -192,7 +192,7 @@ class CcpClient():
resp = self._recv_dto(0.025) resp = self._recv_dto(0.025)
# mta_addr_ext = resp[0] # mta_addr_ext = resp[0]
mta_addr = struct.unpack(f"{self.byte_order.value}I", resp[1:5])[0] mta_addr = struct.unpack(f"{self.byte_order.value}I", resp[1:5])[0]
return mta_addr return mta_addr # type: ignore
def upload(self, size: int) -> bytes: def upload(self, size: int) -> bytes:
if size > 5: if size > 5:
@ -296,7 +296,7 @@ class CcpClient():
resp = self._recv_dto(0.1) resp = self._recv_dto(0.1)
# mta_addr_ext = resp[0] # mta_addr_ext = resp[0]
mta_addr = struct.unpack(f"{self.byte_order.value}I", resp[1:5])[0] mta_addr = struct.unpack(f"{self.byte_order.value}I", resp[1:5])[0]
return mta_addr return mta_addr # type: ignore
def program_6_bytes(self, data: bytes) -> int: def program_6_bytes(self, data: bytes) -> int:
if len(data) != 6: if len(data) != 6:
@ -305,7 +305,7 @@ class CcpClient():
resp = self._recv_dto(0.1) resp = self._recv_dto(0.1)
# mta_addr_ext = resp[0] # mta_addr_ext = resp[0]
mta_addr = struct.unpack(f"{self.byte_order.value}I", resp[1:5])[0] mta_addr = struct.unpack(f"{self.byte_order.value}I", resp[1:5])[0]
return mta_addr return mta_addr # type: ignore
def move_memory_block(self, size: int) -> None: def move_memory_block(self, size: int) -> None:
self._send_cro(COMMAND_CODE.MOVE, struct.pack(f"{self.byte_order.value}I", size)) self._send_cro(COMMAND_CODE.MOVE, struct.pack(f"{self.byte_order.value}I", size))

View File

@ -37,7 +37,8 @@ class PandaSpiDFU:
elif data != ACK: elif data != ACK:
raise Exception("Missing ACK") raise Exception("Missing ACK")
def _cmd(self, cmd, data=None, read_bytes=0): def _cmd(self, cmd, data=None, read_bytes=0) -> bytes:
ret = b""
with self.dev.acquire() as spi: with self.dev.acquire() as spi:
# sync # sync
spi.xfer([SYNC, ]) spi.xfer([SYNC, ])
@ -53,7 +54,6 @@ class PandaSpiDFU:
self._get_ack(spi, timeout=20) self._get_ack(spi, timeout=20)
# receive # receive
ret = None
if read_bytes > 0: if read_bytes > 0:
# send busy byte # send busy byte
ret = spi.xfer([0x00, ]*(read_bytes + 1))[1:] ret = spi.xfer([0x00, ]*(read_bytes + 1))[1:]

View File

@ -1,12 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from typing import Optional
from panda import Panda from panda import Panda
p = Panda() if __name__ == "__main__":
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p = Panda()
p.set_gmlan(bus=2) p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
#p.can_send(0xaaa, b"\x00\x00", bus=3) p.set_gmlan(bus=2)
last_add = None #p.can_send(0xaaa, b"\x00\x00", bus=3)
while 1: last_add: Optional[int] = None
while True:
ret = p.can_recv() ret = p.can_recv()
if len(ret) > 0: if len(ret) > 0:
add = ret[0][0] add = ret[0][0]

View File

@ -53,6 +53,6 @@ if __name__ == "__main__":
if not replay_drive(lr, mode, param, alt_exp): if not replay_drive(lr, mode, param, alt_exp):
failed.append(route) failed.append(route)
for f in failed: # type: ignore for f in failed:
print(f"\n**** failed on {f} ****") print(f"\n**** failed on {f} ****")
assert len(failed) == 0, "\nfailed on %d logs" % len(failed) assert len(failed) == 0, "\nfailed on %d logs" % len(failed)