mypy: enable --warn-unreachable (#24282)

* Optional solves mypy assuming None is always None

* oops

* spaces

* Update registration.py

* fix local error

Co-authored-by: Willem Melching <willem.melching@gmail.com>
old-commit-hash: b8b15d5cf1
taco
grekiki 3 years ago committed by GitHub
parent 373ac5ce3d
commit cc943ac9a5
  1. 2
      .pre-commit-config.yaml
  2. 4
      selfdrive/athena/registration.py
  3. 3
      selfdrive/debug/internal/measure_modeld_packet_drop.py
  4. 9
      selfdrive/debug/live_cpu_and_temp.py
  5. 2
      selfdrive/hardware/base.py
  6. 2
      selfdrive/manager/build.py
  7. 2
      selfdrive/manager/process.py
  8. 2
      tools/replay/can_replay.py
  9. 1
      tools/sim/bridge.py

@ -22,6 +22,8 @@ repos:
exclude: '^(pyextra/)|(cereal/)|(rednose/)|(panda/)|(laika/)|(opendbc/)|(laika_repo/)|(rednose_repo/)/'
additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites',
'types-pycurl']
args:
- --warn-unreachable
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:

@ -3,6 +3,7 @@ import time
import json
import jwt
from pathlib import Path
from typing import Optional
from datetime import datetime, timedelta
from common.api import api_get
@ -48,7 +49,8 @@ def register(show_spinner=False) -> str:
# Block until we get the imei
serial = HARDWARE.get_serial()
start_time = time.monotonic()
imei1, imei2 = None, None
imei1: Optional[str] = None
imei2: Optional[str] = None
while imei1 is None and imei2 is None:
try:
imei1, imei2 = HARDWARE.get_imei(0), HARDWARE.get_imei(1)

@ -1,11 +1,12 @@
#!/usr/bin/env python3
import cereal.messaging as messaging
from typing import Optional
if __name__ == "__main__":
modeld_sock = messaging.sub_sock("modelV2")
last_frame_id = None
start_t = None
start_t: Optional[int] = None
frame_cnt = 0
dropped = 0

@ -1,9 +1,10 @@
#!/usr/bin/env python3
import argparse
import capnp
from cereal.messaging import SubMaster
from common.numpy_fast import mean
from typing import Optional
def cputime_total(ct):
return ct.user + ct.nice + ct.system + ct.idle + ct.iowait + ct.irq + ct.softirq
@ -40,8 +41,8 @@ if __name__ == "__main__":
total_times = [0.]*8
busy_times = [0.]*8
prev_proclog = None
prev_proclog_t = None
prev_proclog: Optional[capnp._DynamicStructReader] = None
prev_proclog_t: Optional[int] = None
while True:
sm.update()
@ -73,7 +74,7 @@ if __name__ == "__main__":
print(f"CPU {100.0 * mean(cores):.2f}% - RAM: {last_mem:.2f}% - Temp {last_temp:.2f}C")
if args.cpu and prev_proclog is not None:
if args.cpu and prev_proclog is not None and prev_proclog_t is not None:
procs = {}
dt = (sm.logMonoTime['procLog'] - prev_proclog_t) / 1e9
for proc in m.procs:

@ -44,7 +44,7 @@ class HardwareBase(ABC):
pass
@abstractmethod
def get_imei(self, slot):
def get_imei(self, slot) -> str:
pass
@abstractmethod

@ -29,7 +29,7 @@ def build(spinner: Spinner, dirty: bool = False) -> None:
j_flag = "" if nproc is None else f"-j{nproc - 1}"
for retry in [True, False]:
scons = subprocess.Popen(["scons", j_flag, "--cache-populate"], cwd=BASEDIR, env=env, stderr=subprocess.PIPE)
scons: subprocess.Popen = subprocess.Popen(["scons", j_flag, "--cache-populate"], cwd=BASEDIR, env=env, stderr=subprocess.PIPE)
assert scons.stderr is not None
compile_output = []

@ -78,7 +78,7 @@ class ManagerProcess(ABC):
name = ""
last_watchdog_time = 0
watchdog_max_dt = None
watchdog_max_dt: Optional[int] = None
watchdog_seen = False
shutting_down = False

@ -83,7 +83,7 @@ def connect():
if __name__ == "__main__":
if PandaJungle is None:
print("\33[31m", "WARNING: cannot connect to jungles. Clone the jungle library to enable support:", "\033[0m")
print("\33[31m", "WARNING: cannot connect to jungles. Clone the jungle library to enable support:", "\033[0m") # type: ignore
print("\033[34m", f"cd {BASEDIR} && git clone https://github.com/commaai/panda_jungle", "\033[0m")
print("Loading log...")

@ -489,7 +489,6 @@ if __name__ == "__main__":
# start input poll for joystick
from lib.manual_ctrl import wheel_poll_thread
wheel_poll_thread(q)
p.join()
else:
# start input poll for keyboard
from lib.keyboard_ctrl import keyboard_poll_thread

Loading…
Cancel
Save