fixes for mypy check for return-any

This commit is contained in:
Willem Melching 2022-05-12 14:22:58 +02:00
parent 1d2127876d
commit d5bd81e5b5
2 changed files with 13 additions and 11 deletions

View File

@ -8,6 +8,7 @@ import time
import traceback import traceback
import sys import sys
from functools import wraps from functools import wraps
from typing import Optional
from .dfu import PandaDFU, MCU_TYPE_F2, MCU_TYPE_F4, MCU_TYPE_H7 # pylint: disable=import-error from .dfu import PandaDFU, MCU_TYPE_F2, MCU_TYPE_F4, MCU_TYPE_H7 # pylint: disable=import-error
from .flash_release import flash_release # noqa pylint: disable=import-error from .flash_release import flash_release # noqa pylint: disable=import-error
from .update import ensure_st_up_to_date # noqa pylint: disable=import-error from .update import ensure_st_up_to_date # noqa pylint: disable=import-error
@ -120,7 +121,7 @@ class ALTERNATIVE_EXPERIENCE:
DISABLE_STOCK_AEB = 2 DISABLE_STOCK_AEB = 2
RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX = 8 RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX = 8
class Panda(object): class Panda:
# matches cereal.car.CarParams.SafetyModel # matches cereal.car.CarParams.SafetyModel
SAFETY_SILENT = 0 SAFETY_SILENT = 0
@ -195,7 +196,7 @@ class Panda(object):
FLAG_TESLA_POWERTRAIN = 1 FLAG_TESLA_POWERTRAIN = 1
FLAG_TESLA_LONG_CONTROL = 2 FLAG_TESLA_LONG_CONTROL = 2
def __init__(self, serial=None, claim=True): def __init__(self, serial: Optional[str] = None, claim: bool = True):
self._serial = serial self._serial = serial
self._handle = None self._handle = None
self.connect(claim) self.connect(claim)
@ -215,7 +216,7 @@ class Panda(object):
while 1: while 1:
try: try:
for device in context.getDeviceList(skip_on_error=True): for device in context.getDeviceList(skip_on_error=True):
if device.getVendorID() == 0xbbaa and device.getProductID() in [0xddcc, 0xddee]: if device.getVendorID() == 0xbbaa and device.getProductID() in (0xddcc, 0xddee):
try: try:
this_serial = device.getSerialNumber() this_serial = device.getSerialNumber()
except Exception: except Exception:
@ -225,7 +226,7 @@ class Panda(object):
print("opening device", self._serial, hex(device.getProductID())) print("opening device", self._serial, hex(device.getProductID()))
self.bootstub = device.getProductID() == 0xddee self.bootstub = device.getProductID() == 0xddee
self._handle = device.open() self._handle = device.open()
if sys.platform not in ["win32", "cygwin", "msys", "darwin"]: if sys.platform not in ("win32", "cygwin", "msys", "darwin"):
self._handle.setAutoDetachKernelDriver(True) self._handle.setAutoDetachKernelDriver(True)
if claim: if claim:
self._handle.claimInterface(0) self._handle.claimInterface(0)
@ -328,7 +329,7 @@ class Panda(object):
if reconnect: if reconnect:
self.reconnect() self.reconnect()
def recover(self, timeout=None, reset=True): def recover(self, timeout: Optional[int] = None, reset: bool = True) -> bool:
if reset: if reset:
self.reset(enter_bootstub=True) self.reset(enter_bootstub=True)
self.reset(enter_bootloader=True) self.reset(enter_bootloader=True)
@ -354,7 +355,7 @@ class Panda(object):
ret = [] ret = []
try: try:
for device in context.getDeviceList(skip_on_error=True): for device in context.getDeviceList(skip_on_error=True):
if device.getVendorID() == 0xbbaa and device.getProductID() in [0xddcc, 0xddee]: if device.getVendorID() == 0xbbaa and device.getProductID() in (0xddcc, 0xddee):
try: try:
ret.append(device.getSerialNumber()) ret.append(device.getSerialNumber())
except Exception: except Exception:
@ -409,7 +410,7 @@ class Panda(object):
return self._handle.controlRead(Panda.REQUEST_IN, 0xd6, 0, 0, 0x40).decode('utf8') return self._handle.controlRead(Panda.REQUEST_IN, 0xd6, 0, 0, 0x40).decode('utf8')
@staticmethod @staticmethod
def get_signature_from_firmware(fn): def get_signature_from_firmware(fn) -> bytes:
f = open(fn, 'rb') f = open(fn, 'rb')
f.seek(-128, 2) # Seek from end of file f.seek(-128, 2) # Seek from end of file
return f.read(128) return f.read(128)
@ -465,11 +466,11 @@ class Panda(object):
def has_obd(self): def has_obd(self):
return (self.is_uno() or self.is_dos() or self.is_black() or self.is_red()) return (self.is_uno() or self.is_dos() or self.is_black() or self.is_red())
def has_canfd(self): def has_canfd(self) -> bool:
return self.get_type() in Panda.H7_DEVICES return self.get_type() in Panda.H7_DEVICES
def is_internal(self): def is_internal(self) -> bool:
return self.get_type() in [Panda.HW_TYPE_UNO, Panda.HW_TYPE_DOS] return self.get_type() in (Panda.HW_TYPE_UNO, Panda.HW_TYPE_DOS)
def get_serial(self): def get_serial(self):
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 0, 0, 0x20) dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 0, 0, 0x20)
@ -511,7 +512,7 @@ class Panda(object):
# TODO: check panda type # TODO: check panda type
if bus is None: if bus is None:
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 0, 0, b'') self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 0, 0, b'')
elif bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]: elif bus in (Panda.GMLAN_CAN2, Panda.GMLAN_CAN3):
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 1, bus, b'') self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 1, bus, b'')
def set_obd(self, obd): def set_obd(self, obd):

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# type: ignore
from panda import Panda from panda import Panda
from hexdump import hexdump from hexdump import hexdump