Skip to content

all: Fix ruff rules C4, PERF401, and PLC0206. #16776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions examples/bluetooth/ble_advertising.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ def decode_name(payload):


def decode_services(payload):
services = []
for u in decode_field(payload, _ADV_TYPE_UUID16_COMPLETE):
services.append(bluetooth.UUID(struct.unpack("<h", u)[0]))
for u in decode_field(payload, _ADV_TYPE_UUID32_COMPLETE):
services.append(bluetooth.UUID(struct.unpack("<d", u)[0]))
for u in decode_field(payload, _ADV_TYPE_UUID128_COMPLETE):
services.append(bluetooth.UUID(u))
services = [
bluetooth.UUID(struct.unpack("<h", u)[0])
for u in decode_field(payload, _ADV_TYPE_UUID16_COMPLETE)
]
services.extend(
bluetooth.UUID(struct.unpack("<d", u)[0])
for u in decode_field(payload, _ADV_TYPE_UUID32_COMPLETE)
)
services.extend(bluetooth.UUID(u) for u in decode_field(payload, _ADV_TYPE_UUID128_COMPLETE))
return services


Expand Down
10 changes: 4 additions & 6 deletions ports/esp32/boards/UM_TINYPICO/modules/dotstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,10 @@ def __setitem__(self, index, val):

def __getitem__(self, index):
if isinstance(index, slice):
out = []
for in_i in range(*index.indices(self._n)):
out.append(
tuple(self._buf[in_i * 4 + (3 - i) + START_HEADER_SIZE] for i in range(3))
)
return out
return [
tuple(self._buf[in_i * 4 + (3 - i) + START_HEADER_SIZE] for i in range(3))
for in_i in range(*index.indices(self._n))
]
if index < 0:
index += len(self)
if index >= self._n or index < 0:
Expand Down
4 changes: 2 additions & 2 deletions ports/nrf/boards/make-pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,15 @@ def print_header(self, out_header):
print("extern const pin_obj_t * const pin_adc3[];", file=out_header)

def print_af_hdr(self, out_af_const):
af_hdr_set = set([])
af_hdr_set = set()
mux_name_width = 0
for named_pin in self.cpu_pins:
pin = named_pin.pin()
if pin.is_board_pin():
for af in pin.alt_fn:
if af.is_supported():
mux_name = af.mux_name()
af_hdr_set |= set([mux_name])
af_hdr_set |= {mux_name}
if len(mux_name) > mux_name_width:
mux_name_width = len(mux_name)
for mux_name in sorted(af_hdr_set):
Expand Down
11 changes: 6 additions & 5 deletions ports/nrf/examples/powerup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ def bytes_to_str(bytes):
def get_device_names(scan_entries):
dev_names = []
for e in scan_entries:
scan = e.getScanData()
if scan:
for s in scan:
if s[0] == constants.ad_types.AD_TYPE_COMPLETE_LOCAL_NAME:
dev_names.append((e, bytes_to_str(s[2])))
scan = e.getScanData() or []
dev_names.extend(
(e, bytes_to_str(s[2]))
for s in scan
if s[0] == constants.ad_types.AD_TYPE_COMPLETE_LOCAL_NAME
)
return dev_names


Expand Down
11 changes: 6 additions & 5 deletions ports/nrf/examples/ubluepy_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ def bytes_to_str(bytes):
def get_device_names(scan_entries):
dev_names = []
for e in scan_entries:
scan = e.getScanData()
if scan:
for s in scan:
if s[0] == constants.ad_types.AD_TYPE_COMPLETE_LOCAL_NAME:
dev_names.append((e, bytes_to_str(s[2])))
scan = e.getScanData() or []
dev_names.extend(
(e, bytes_to_str(s[2]))
for s in scan
if s[0] == constants.ad_types.AD_TYPE_COMPLETE_LOCAL_NAME
)
return dev_names


Expand Down
4 changes: 2 additions & 2 deletions ports/stm32/boards/plli2svalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ def main():

# Select MCU parameters
mcu = mcu_default
for m in mcu_table:
for m, new_mcu in mcu_table.items():
if mcu_series.startswith(m):
mcu = mcu_table[m]
mcu = new_mcu
break
plli2s_table = compute_plli2s_table(hse, pllm)
if c_table:
Expand Down
4 changes: 2 additions & 2 deletions ports/stm32/boards/pllvalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ def main():

# Select MCU parameters
mcu = mcu_default
for m in mcu_table:
for m, new_mcu in mcu_table.items():
if mcu_series.startswith(m):
mcu = mcu_table[m]
mcu = new_mcu
break

# Relax constraint on PLLQ being 48MHz on MCUs which have separate PLLs for 48MHz
Expand Down
6 changes: 4 additions & 2 deletions ports/stm32/make-stmconst.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ def parse_file(filename):
if m[0] == "IO reg":
regs.append((reg, offset, bits, comment))
else:
for i in range(int(d["array"])):
regs.append((reg + str(i), offset + i * bits // 8, bits, comment))
regs.extend(
(reg + str(i), offset + i * bits // 8, bits, comment)
for i in range(int(d["array"]))
)
m = lexer.next_match()
if m[0] in ("}", "} _t"):
pass
Expand Down
2 changes: 1 addition & 1 deletion tools/codeformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def main():
# Filter against the default list of files. This is a little fiddly
# because we need to apply both the inclusion globs given in PATHS
# as well as the EXCLUSIONS, and use absolute paths
files = set(os.path.abspath(f) for f in files)
files = {os.path.abspath(f) for f in files}
all_files = set(list_files(PATHS, EXCLUSIONS, TOP))
if args.v: # In verbose mode, log any files we're skipping
for f in files - all_files:
Expand Down
4 changes: 2 additions & 2 deletions tools/dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def build(file, targets, device=DEFAULT_DEVICE):
)
data += tdata
data = struct.pack("<5sBIB", b"DfuSe", 1, len(data) + 11, len(targets)) + data
v, d = map(lambda x: int(x, 0) & 0xFFFF, device.split(":", 1))
v, d = (int(x, 0) & 0xFFFF for x in device.split(":", 1))
data += struct.pack("<4H3sB", 0, d, v, 0x011A, b"UFD", 16)
crc = compute_crc(data)
data += struct.pack("<I", crc)
Expand Down Expand Up @@ -147,7 +147,7 @@ def build(file, targets, device=DEFAULT_DEVICE):
if options.device:
device = options.device
try:
v, d = map(lambda x: int(x, 0) & 0xFFFF, device.split(":", 1))
v, d = (int(x, 0) & 0xFFFF for x in device.split(":", 1))
except:
print("Invalid device '%s'." % device)
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion tools/insert-usb-ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def parse_usb_ids(filename):
rv = dict()
rv = {}
for line in open(filename).readlines():
line = line.rstrip("\r\n")
match = re.match(r"^#define\s+(\w+)\s+\(0x([0-9A-Fa-f]+)\)$", line)
Expand Down
8 changes: 2 additions & 6 deletions tools/mpy-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,15 +1374,11 @@ def read_mpy(filename):

# Read qstrs and construct qstr table.
qstr_table_file_offset = reader.tell()
qstr_table = []
for i in range(n_qstr):
qstr_table.append(read_qstr(reader, segments))
qstr_table = [read_qstr(reader, segments) for _ in range(n_qstr)]

# Read objects and construct object table.
obj_table_file_offset = reader.tell()
obj_table = []
for i in range(n_obj):
obj_table.append(read_obj(reader, segments))
obj_table = [read_obj(reader, segments) for _ in range(n_obj)]

# Compute the compiled-module escaped name.
cm_escaped_name = qstr_table[0].str.replace("/", "_")[:-3]
Expand Down
7 changes: 3 additions & 4 deletions tools/uf2conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def convert_from_uf2(buf):
if blockno == (numblocks - 1):
print("--- UF2 File Header Info ---")
families = load_families()
for family_hex in families_found.keys():
for family_hex, target_address in families_found.items():
family_short_name = ""
for name, value in families.items():
if value == family_hex:
Expand All @@ -128,7 +128,7 @@ def convert_from_uf2(buf):
family_short_name, family_hex
)
)
print("Target Address is 0x{:08x}".format(families_found[family_hex]))
print("Target Address is 0x{:08x}".format(target_address))
if all_flags_same:
print("All block flag values consistent, 0x{:04x}".format(hd[2]))
else:
Expand Down Expand Up @@ -282,8 +282,7 @@ def get_drives():
tmp = rootpath + "/" + os.environ["USER"]
if os.path.isdir(tmp):
rootpath = tmp
for d in os.listdir(rootpath):
drives.append(os.path.join(rootpath, d))
drives.extend(os.path.join(rootpath, d) for d in os.listdir(rootpath))

def has_info(d):
try:
Expand Down
Loading