Skip to content

Commit 4da6e6f

Browse files
committed
all: Lint Python code with ruff.
Signed-off-by: Christian Clauss <cclauss@me.com>
1 parent 752ce66 commit 4da6e6f

File tree

24 files changed

+139
-46
lines changed

24 files changed

+139
-46
lines changed

.github/workflows/build_packages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-python@v1
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v4
1414
- name: Setup environment
1515
run: source tools/ci.sh && ci_build_packages_setup
1616
- name: Check manifest files

.github/workflows/cleanup_published_packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ jobs:
77
runs-on: ubuntu-latest
88
if: vars.MICROPY_PUBLISH_MIP_INDEX
99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v3
1111
- name: Clean up published files
1212
run: source tools/ci.sh && ci_cleanup_package_index ${{ github.event.ref }}

.github/workflows/code_formatting.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ jobs:
66
build:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
10-
- uses: actions/setup-python@v1
9+
- uses: actions/checkout@v3
10+
- run: pip install --user ruff
11+
- run: ruff --format=github .
12+
- uses: actions/setup-python@v4
1113
- name: Install packages
1214
run: source tools/ci.sh && ci_code_formatting_setup
1315
- name: Run code formatting

micropython/aioespnow/aioespnow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ class AIOESPNow(espnow.ESPNow):
1111
# Read one ESPNow message
1212
async def arecv(self):
1313
yield asyncio.core._io_queue.queue_read(self)
14-
return self.recv(0) # type: ignore
14+
return self.recv(0) # type: ignore[misc]
1515

1616
async def airecv(self):
1717
yield asyncio.core._io_queue.queue_read(self)
18-
return self.irecv(0) # type: ignore
18+
return self.irecv(0) # type: ignore[misc]
1919

2020
async def asend(self, mac, msg=None, sync=None):
2121
if msg is None:
2222
msg, mac = mac, None # If msg is None: swap mac and msg
2323
yield asyncio.core._io_queue.queue_write(self)
24-
return self.send(mac, msg, sync) # type: ignore
24+
return self.send(mac, msg, sync) # type: ignore[misc]
2525

2626
# "async for" support
2727
def __aiter__(self):

micropython/bluetooth/aioble/examples/l2cap_file_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def download(self, path, dest):
8787

8888
send_seq = await self._command(_COMMAND_SEND, path.encode())
8989

90-
with open(dest, "wb") as f:
90+
with open(dest, "wb") as f: # noqa: ASYNC101
9191
total = 0
9292
buf = bytearray(self._channel.our_mtu)
9393
mv = memoryview(buf)

micropython/bluetooth/aioble/examples/l2cap_file_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def l2cap_task(connection):
8282

8383
if send_file:
8484
print("Sending:", send_file)
85-
with open(send_file, "rb") as f:
85+
with open(send_file, "rb") as f: # noqa: ASYNC101
8686
buf = bytearray(channel.peer_mtu)
8787
mv = memoryview(buf)
8888
while n := f.readinto(buf):

micropython/drivers/codec/wm8960/wm8960.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def set_data_route(self, route):
578578
raise ValueError("Invalid route")
579579

580580
def set_left_input(self, input):
581-
if not input in self._input_config_table.keys():
581+
if input not in self._input_config_table:
582582
raise ValueError("Invalid input")
583583

584584
input = self._input_config_table[input]
@@ -595,7 +595,7 @@ def set_left_input(self, input):
595595
regs[_LINVOL] = input[1]
596596

597597
def set_right_input(self, input):
598-
if not input in self._input_config_table.keys():
598+
if input not in self._input_config_table:
599599
raise ValueError("Invalid input name")
600600

601601
input = self._input_config_table[input]
@@ -629,7 +629,7 @@ def config_data_format(self, sysclk, sample_rate, bits):
629629
self.regs[_IFACE1] = (_IFACE1_WL_MASK, wl << _IFACE1_WL_SHIFT)
630630

631631
def volume(self, module, volume_l=None, volume_r=None):
632-
if not module in self._volume_config_table.keys():
632+
if module not in self._volume_config_table:
633633
raise ValueError("Invalid module")
634634

635635
if volume_l is None: # get volume
@@ -644,7 +644,7 @@ def volume(self, module, volume_l=None, volume_r=None):
644644

645645
if not ((0 <= volume_l <= 100) and (0 <= volume_r <= 100)):
646646
raise ValueError("Invalid value for volume")
647-
elif not module in self._volume_config_table.keys():
647+
elif module not in self._volume_config_table:
648648
raise ValueError("Invalid module")
649649

650650
vol_max, regnum, flags = self._volume_config_table[module]

micropython/drivers/imu/bmi270/bmi270.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,13 @@ def __init__(
524524
# Sanity checks
525525
if not self._use_i2c:
526526
raise ValueError("SPI mode is not supported")
527-
if not gyro_odr in ODR:
527+
if gyro_odr not in ODR:
528528
raise ValueError("Invalid gyro sampling rate: %d" % gyro_odr)
529-
if not gyro_scale in GYRO_SCALE:
529+
if gyro_scale not in GYRO_SCALE:
530530
raise ValueError("Invalid gyro scaling: %d" % gyro_scale)
531-
if not accel_odr in ODR:
531+
if accel_odr not in ODR:
532532
raise ValueError("Invalid accelerometer sampling rate: %d" % accel_odr)
533-
if not accel_scale in ACCEL_SCALE:
533+
if accel_scale not in ACCEL_SCALE:
534534
raise ValueError("Invalid accelerometer scaling: %d" % accel_scale)
535535
if self._read_reg(_CHIP_ID) != 0x24:
536536
raise OSError("No BMI270 device was found at address 0x%x" % (self.address))

micropython/drivers/imu/bmm150/bmm150.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(
8080
# Sanity checks
8181
if not self._use_i2c:
8282
raise ValueError("SPI mode is not supported")
83-
if not magnet_odr in _ODR:
83+
if magnet_odr not in _ODR:
8484
raise ValueError("Invalid sampling rate: %d" % magnet_odr)
8585

8686
# Perform soft reset, and power on.

micropython/drivers/imu/lsm6dsox/lsm6dsox.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,20 @@ def __init__(
130130
accel_odr = round(accel_odr, 2)
131131

132132
# Sanity checks
133-
if not gyro_odr in ODR:
133+
if gyro_odr not in ODR:
134134
raise ValueError("Invalid sampling rate: %d" % gyro_odr)
135-
if not gyro_scale in SCALE_GYRO:
135+
if gyro_scale not in SCALE_GYRO:
136136
raise ValueError("invalid gyro scaling: %d" % gyro_scale)
137-
if not accel_odr in ODR:
137+
if accel_odr not in ODR:
138138
raise ValueError("Invalid sampling rate: %d" % accel_odr)
139-
if not accel_scale in SCALE_ACCEL:
139+
if accel_scale not in SCALE_ACCEL:
140140
raise ValueError("invalid accelerometer scaling: %d" % accel_scale)
141141

142142
# Soft-reset the device.
143143
self.reset()
144144

145145
# Load and configure MLC if UCF file is provided
146-
if ucf != None:
146+
if ucf is not None:
147147
self.load_mlc(ucf)
148148

149149
# Set Gyroscope datarate and scale.

0 commit comments

Comments
 (0)