diff --git a/common/logging_extra.py b/common/logging_extra.py index 899ad7a391..e2637d2e05 100644 --- a/common/logging_extra.py +++ b/common/logging_extra.py @@ -65,7 +65,7 @@ class SwagFormatter(logging.Formatter): return record_dict - def format(self, record): + def format(self, record): # noqa: A003 if self.swaglogger is None: raise Exception("must set swaglogger before calling format()") return json_robust_dumps(self.format_dict(record)) @@ -95,7 +95,7 @@ class SwagLogFileFormatter(SwagFormatter): k += "$a" return k, v - def format(self, record): + def format(self, record): # noqa: A003 if isinstance(record, str): v = json.loads(record) else: diff --git a/docs/conf.py b/docs/conf.py index fea921de1f..345d27f6ad 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,7 +29,7 @@ VERSION = get_version() # -- Project information ----------------------------------------------------- project = 'openpilot docs' -copyright = '2021, comma.ai' +copyright = '2021, comma.ai' # noqa: A001 author = 'comma.ai' version = VERSION release = VERSION diff --git a/pyproject.toml b/pyproject.toml index a07adde85f..74084cbc93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -197,7 +197,7 @@ build-backend = "poetry.core.masonry.api" # https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml [tool.ruff] -select = ["E", "F", "W", "PIE", "C4", "ISC", "RUF100"] +select = ["E", "F", "W", "PIE", "C4", "ISC", "RUF100", "A"] ignore = ["W292", "E741", "E402", "C408", "ISC003"] line-length = 160 target-version="py311" diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index 780d2ab900..6ef32f8a5b 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -85,7 +85,7 @@ class UploadItem: url: str headers: Dict[str, str] created_at: int - id: Optional[str] + id: Optional[str] # noqa: A003 (to match the response from the remote server) retry_count: int = 0 current: bool = False progress: float = 0 diff --git a/selfdrive/car/docs_definitions.py b/selfdrive/car/docs_definitions.py index 3a6aa5e2db..2220205e8f 100644 --- a/selfdrive/car/docs_definitions.py +++ b/selfdrive/car/docs_definitions.py @@ -50,7 +50,7 @@ class BasePart: class EnumBase(Enum): @property - def type(self): + def part_type(self): return PartType(self.__class__) diff --git a/selfdrive/car/tests/test_docs.py b/selfdrive/car/tests/test_docs.py index 80f38056cd..6e4a58149c 100755 --- a/selfdrive/car/tests/test_docs.py +++ b/selfdrive/car/tests/test_docs.py @@ -84,7 +84,7 @@ class TestCarDocs(unittest.TestCase): if car.name == "comma body": raise unittest.SkipTest - car_part_type = [p.type for p in car.car_parts.all_parts()] + car_part_type = [p.part_type for p in car.car_parts.all_parts()] car_parts = list(car.car_parts.all_parts()) self.assertTrue(len(car_parts) > 0, f"Need to specify car parts: {car.name}") self.assertTrue(car_part_type.count(PartType.connector) == 1, f"Need to specify one harness connector: {car.name}") diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 79ec310d58..8084b18ff6 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -351,7 +351,7 @@ class Controls: # generic catch-all. ideally, a more specific event should be added above instead can_rcv_timeout = self.can_rcv_timeout_counter >= 5 - has_disable_events = self.events.any(ET.NO_ENTRY) and (self.events.any(ET.SOFT_DISABLE) or self.events.any(ET.IMMEDIATE_DISABLE)) + has_disable_events = self.events.contains(ET.NO_ENTRY) and (self.events.contains(ET.SOFT_DISABLE) or self.events.contains(ET.IMMEDIATE_DISABLE)) no_system_errors = (not has_disable_events) or (len(self.events) == num_events) if (not self.sm.all_checks() or can_rcv_timeout) and no_system_errors: if not self.sm.all_alive(): @@ -487,29 +487,29 @@ class Controls: # ENABLED, SOFT DISABLING, PRE ENABLING, OVERRIDING if self.state != State.disabled: # user and immediate disable always have priority in a non-disabled state - if self.events.any(ET.USER_DISABLE): + if self.events.contains(ET.USER_DISABLE): self.state = State.disabled self.current_alert_types.append(ET.USER_DISABLE) - elif self.events.any(ET.IMMEDIATE_DISABLE): + elif self.events.contains(ET.IMMEDIATE_DISABLE): self.state = State.disabled self.current_alert_types.append(ET.IMMEDIATE_DISABLE) else: # ENABLED if self.state == State.enabled: - if self.events.any(ET.SOFT_DISABLE): + if self.events.contains(ET.SOFT_DISABLE): self.state = State.softDisabling self.soft_disable_timer = int(SOFT_DISABLE_TIME / DT_CTRL) self.current_alert_types.append(ET.SOFT_DISABLE) - elif self.events.any(ET.OVERRIDE_LATERAL) or self.events.any(ET.OVERRIDE_LONGITUDINAL): + elif self.events.contains(ET.OVERRIDE_LATERAL) or self.events.contains(ET.OVERRIDE_LONGITUDINAL): self.state = State.overriding self.current_alert_types += [ET.OVERRIDE_LATERAL, ET.OVERRIDE_LONGITUDINAL] # SOFT DISABLING elif self.state == State.softDisabling: - if not self.events.any(ET.SOFT_DISABLE): + if not self.events.contains(ET.SOFT_DISABLE): # no more soft disabling condition, so go back to ENABLED self.state = State.enabled @@ -521,32 +521,32 @@ class Controls: # PRE ENABLING elif self.state == State.preEnabled: - if not self.events.any(ET.PRE_ENABLE): + if not self.events.contains(ET.PRE_ENABLE): self.state = State.enabled else: self.current_alert_types.append(ET.PRE_ENABLE) # OVERRIDING elif self.state == State.overriding: - if self.events.any(ET.SOFT_DISABLE): + if self.events.contains(ET.SOFT_DISABLE): self.state = State.softDisabling self.soft_disable_timer = int(SOFT_DISABLE_TIME / DT_CTRL) self.current_alert_types.append(ET.SOFT_DISABLE) - elif not (self.events.any(ET.OVERRIDE_LATERAL) or self.events.any(ET.OVERRIDE_LONGITUDINAL)): + elif not (self.events.contains(ET.OVERRIDE_LATERAL) or self.events.contains(ET.OVERRIDE_LONGITUDINAL)): self.state = State.enabled else: self.current_alert_types += [ET.OVERRIDE_LATERAL, ET.OVERRIDE_LONGITUDINAL] # DISABLED elif self.state == State.disabled: - if self.events.any(ET.ENABLE): - if self.events.any(ET.NO_ENTRY): + if self.events.contains(ET.ENABLE): + if self.events.contains(ET.NO_ENTRY): self.current_alert_types.append(ET.NO_ENTRY) else: - if self.events.any(ET.PRE_ENABLE): + if self.events.contains(ET.PRE_ENABLE): self.state = State.preEnabled - elif self.events.any(ET.OVERRIDE_LATERAL) or self.events.any(ET.OVERRIDE_LONGITUDINAL): + elif self.events.contains(ET.OVERRIDE_LATERAL) or self.events.contains(ET.OVERRIDE_LONGITUDINAL): self.state = State.overriding else: self.state = State.enabled @@ -585,7 +585,7 @@ class Controls: standstill = CS.vEgo <= max(self.CP.minSteerSpeed, MIN_LATERAL_CONTROL_SPEED) or CS.standstill CC.latActive = self.active and not CS.steerFaultTemporary and not CS.steerFaultPermanent and \ (not standstill or self.joystick_mode) - CC.longActive = self.enabled and not self.events.any(ET.OVERRIDE_LONGITUDINAL) and self.CP.openpilotLongitudinalControl + CC.longActive = self.enabled and not self.events.contains(ET.OVERRIDE_LONGITUDINAL) and self.CP.openpilotLongitudinalControl actuators = CC.actuators actuators.longControlState = self.LoC.long_control_state @@ -783,7 +783,7 @@ class Controls: controlsState.desiredCurvature = self.desired_curvature controlsState.desiredCurvatureRate = self.desired_curvature_rate controlsState.state = self.state - controlsState.engageable = not self.events.any(ET.NO_ENTRY) + controlsState.engageable = not self.events.contains(ET.NO_ENTRY) controlsState.longControlState = self.LoC.long_control_state controlsState.vPid = float(self.LoC.v_pid) controlsState.vCruise = float(self.v_cruise_helper.v_cruise_kph) diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index f6c9c17a3b..e552e18966 100755 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -67,7 +67,7 @@ class Events: self.events_prev = {k: (v + 1 if k in self.events else 0) for k, v in self.events_prev.items()} self.events = self.static_events.copy() - def any(self, event_type: str) -> bool: + def contains(self, event_type: str) -> bool: return any(event_type in EVENTS.get(e, {}) for e in self.events) def create_alerts(self, event_types: List[str], callback_args=None): diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 83690dbb0d..96d625c2cb 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -54,14 +54,14 @@ class ReplayContext: assert(len(self.pubs) != 0 or self.main_pub is not None) def __enter__(self): - self.open() + self.open_context() return self def __exit__(self, exc_type, exc_obj, exc_tb): - self.close() + self.close_context() - def open(self): + def open_context(self): messaging.toggle_fake_events(True) messaging.set_fake_prefix(self.proc_name) @@ -73,7 +73,7 @@ class ReplayContext: else: self.events = {self.main_pub: messaging.fake_event_handle(self.main_pub, enable=True)} - def close(self): + def close_context(self): del self.events messaging.toggle_fake_events(False) @@ -211,7 +211,7 @@ class ProcessContainer: self.cfg.config_callback(params, self.cfg, all_msgs) self.rc = ReplayContext(self.cfg) - self.rc.open() + self.rc.open_context() self.pm = messaging.PubMaster(self.cfg.pubs) self.sockets = [messaging.sub_sock(s, timeout=100) for s in self.cfg.subs] @@ -237,7 +237,7 @@ class ProcessContainer: with self.prefix: self.process.signal(signal.SIGKILL) self.process.stop() - self.rc.close() + self.rc.close_context() self.prefix.clean_dirs() def run_step(self, msg: capnp._DynamicStructReader, frs: Optional[Dict[str, Any]]) -> List[capnp._DynamicStructReader]: diff --git a/system/ubloxd/tests/ublox.py b/system/ubloxd/tests/ublox.py index 241310cf00..ddfea174b7 100644 --- a/system/ubloxd/tests/ublox.py +++ b/system/ubloxd/tests/ublox.py @@ -324,7 +324,7 @@ class UBloxDescriptor: msg._buf += struct.pack(self.format2, *tuple(f2)) msg._buf += struct.pack(' 0: '''handle corrupted streams''' self._buf = self._buf[1:] @@ -933,7 +933,7 @@ class UBlox: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) self.send_message(CLASS_CFG, MSG_CFG_NAVX5, payload) - def module_reset(self, set, mode): + def module_reset(self, reset, mode): ''' Reset the module for hot/warm/cold start''' - payload = struct.pack('