diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c1c24d1096..90e55e7c7d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,7 @@ repos: entry: mypy language: system types: [python] - args: ['--explicit-package-bases'] + args: ['--explicit-package-bases', '--local-partial-types'] exclude: '^(third_party/)|(cereal/)|(opendbc/)|(panda/)|(rednose/)|(rednose_repo/)|(tinygrad/)|(tinygrad_repo/)|(xx/)' - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.5 diff --git a/scripts/code_stats.py b/scripts/code_stats.py index 59b5724a68..3189cd7cc1 100755 --- a/scripts/code_stats.py +++ b/scripts/code_stats.py @@ -13,7 +13,7 @@ for d in ["cereal", "common", "scripts", "selfdrive", "tools"]: if f.endswith(".py"): pyf.append(os.path.join(root, f)) -imps = set() +imps: set[str] = set() class Analyzer(ast.NodeVisitor): def visit_Import(self, node): diff --git a/tools/bodyteleop/web.py b/tools/bodyteleop/web.py index 717afdeaf8..929cfa26fe 100644 --- a/tools/bodyteleop/web.py +++ b/tools/bodyteleop/web.py @@ -18,11 +18,14 @@ import cereal.messaging as messaging from openpilot.common.basedir import BASEDIR from openpilot.tools.bodyteleop.bodyav import BodyMic, WebClientSpeaker, force_codec, play_sound, MediaBlackhole, EncodedBodyVideo +from typing import Optional + logger = logging.getLogger("pc") logging.basicConfig(level=logging.INFO) -pcs = set() -pm, sm = None, None +pcs: set[RTCPeerConnection] = set() +pm: Optional[messaging.PubMaster] = None +sm: Optional[messaging.SubMaster] = None TELEOPDIR = f"{BASEDIR}/tools/bodyteleop" diff --git a/tools/sim/lib/manual_ctrl.py b/tools/sim/lib/manual_ctrl.py index 1687a2e6ba..04e228c18c 100755 --- a/tools/sim/lib/manual_ctrl.py +++ b/tools/sim/lib/manual_ctrl.py @@ -4,7 +4,7 @@ import array import os import struct from fcntl import ioctl -from typing import NoReturn +from typing import NoReturn, Dict, List # Iterate over the joystick devices. print('Available devices:') @@ -13,8 +13,8 @@ for fn in os.listdir('/dev/input'): print(f' /dev/input/{fn}') # We'll store the states here. -axis_states = {} -button_states = {} +axis_states: Dict[str, float] = {} +button_states: Dict[str, float] = {} # These constants were borrowed from linux/input.h axis_names = { @@ -88,8 +88,8 @@ button_names = { 0x2c3 : 'dpad_down', } -axis_map = [] -button_map = [] +axis_name_list: List[str] = [] +button_name_list: List[str] = [] def wheel_poll_thread(q: 'Queue[str]') -> NoReturn: # Open the joystick device. @@ -119,7 +119,7 @@ def wheel_poll_thread(q: 'Queue[str]') -> NoReturn: for _axis in buf[:num_axes]: axis_name = axis_names.get(_axis, f'unknown(0x{_axis:02x})') - axis_map.append(axis_name) + axis_name_list.append(axis_name) axis_states[axis_name] = 0.0 # Get the button map. @@ -128,11 +128,11 @@ def wheel_poll_thread(q: 'Queue[str]') -> NoReturn: for btn in buf[:num_buttons]: btn_name = button_names.get(btn, f'unknown(0x{btn:03x})') - button_map.append(btn_name) + button_name_list.append(btn_name) button_states[btn_name] = 0 - print('%d axes found: %s' % (num_axes, ', '.join(axis_map))) - print('%d buttons found: %s' % (num_buttons, ', '.join(button_map))) + print('%d axes found: %s' % (num_axes, ', '.join(axis_name_list))) + print('%d buttons found: %s' % (num_buttons, ', '.join(button_name_list))) # Enable FF import evdev @@ -147,7 +147,7 @@ def wheel_poll_thread(q: 'Queue[str]') -> NoReturn: value, mtype, number = struct.unpack('4xhBB', evbuf) # print(mtype, number, value) if mtype & 0x02: # wheel & paddles - axis = axis_map[number] + axis = axis_name_list[number] if axis == "z": # gas fvalue = value / 32767.0 diff --git a/tools/sim/tests/test_carla_bridge.py b/tools/sim/tests/test_carla_bridge.py index dcf2b9c6e2..3a654c993a 100755 --- a/tools/sim/tests/test_carla_bridge.py +++ b/tools/sim/tests/test_carla_bridge.py @@ -2,18 +2,20 @@ import subprocess import time import unittest +from subprocess import Popen from openpilot.selfdrive.manager.helpers import unblock_stdout from openpilot.tools.sim.run_bridge import parse_args from openpilot.tools.sim.bridge.carla.carla_bridge import CarlaBridge from openpilot.tools.sim.tests.test_sim_bridge import SIM_DIR, TestSimBridgeBase +from typing import Optional class TestCarlaBridge(TestSimBridgeBase): """ Tests need Carla simulator to run """ - carla_process = None + carla_process: Optional[Popen] = None def setUp(self): super().setUp()