From 79e57473b20707ca948920fbce473d64dbd8ce25 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 10 Mar 2023 05:59:28 +0100 Subject: [PATCH] all: Fix various Python coding inconsistencies found by ruff. This fixes: - type-comparison (E721): do not compare types, use isinstance(). - string-dot-format-missing-arguments (F524): .format call is missing argument(s) for placeholder(s): {message}. - f-string-missing-placeholders (F541). - is-literal (F632): Use != to compare constant literals. The last one is fixed by just comparing for truthfulness of `state`. --- extmod/uasyncio/funcs.py | 2 +- ports/cc3200/boards/make-pins.py | 2 +- ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py | 2 +- shared/memzip/make-memzip.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extmod/uasyncio/funcs.py b/extmod/uasyncio/funcs.py index 23a585aa94..dc52ad3958 100644 --- a/extmod/uasyncio/funcs.py +++ b/extmod/uasyncio/funcs.py @@ -123,7 +123,7 @@ def gather(*aws, return_exceptions=False): # Either this gather was cancelled, or one of the sub-tasks raised an exception with # return_exceptions==False, so reraise the exception here. - if state is not 0: + if state: raise state # Return the list of return values of each sub-task. diff --git a/ports/cc3200/boards/make-pins.py b/ports/cc3200/boards/make-pins.py index 0cf0d56560..6608be438a 100644 --- a/ports/cc3200/boards/make-pins.py +++ b/ports/cc3200/boards/make-pins.py @@ -124,7 +124,7 @@ class Pins: continue if not row[pin_col].isdigit(): raise ValueError( - "Invalid pin number {:s} in row {:s}".format(row[pin_col]), row + "Invalid pin number {:s} in row {:s}".format(row[pin_col], row) ) # Pin numbers must start from 0 when used with the TI API pin_num = int(row[pin_col]) - 1 diff --git a/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py b/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py index 7cc81b4c68..fe34ce1228 100644 --- a/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py +++ b/ports/stm32/boards/NUCLEO_WB55/rfcore_firmware.py @@ -704,7 +704,7 @@ def check_for_updates(force=False): if fus_uptodate and ws_uptodate and not force: log(f"Already up to date: fus: {current_version_fus}, ws: {current_version_ws}") else: - log(f"Starting firmware update") + log("Starting firmware update") log(f" - fus: {current_version_fus} -> {vers_fus}") log(f" - ws: {current_version_ws} -> {vers_ws}") _write_state(_STATE_WAITING_FOR_FUS) diff --git a/shared/memzip/make-memzip.py b/shared/memzip/make-memzip.py index 9730f5e008..cc0df82077 100755 --- a/shared/memzip/make-memzip.py +++ b/shared/memzip/make-memzip.py @@ -36,7 +36,7 @@ def create_c_from_file(c_filename, zip_filename): break print(' ', end='', file=c_file) for byte in buf: - if type(byte) is types.StringType: + if isinstance(byte, types.StringType): print(' 0x{:02x},'.format(ord(byte)), end='', file=c_file) else: print(' 0x{:02x},'.format(byte), end='', file=c_file)