From 86050c3d7a2db936339ce4bfbd062c3eda7bb193 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 9 Aug 2023 18:51:11 +1000 Subject: [PATCH 1/8] bmm150: Remove broken reset function. Looks like copy-pasta from bmi270 driver. There is a soft reset capability documented in the BMM150 datasheet, but it uses different register bits and I don't have a BMM150 at hand to test it. Found by Ruff checking F821. Signed-off-by: Angus Gratton --- micropython/drivers/imu/bmm150/bmm150.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/micropython/drivers/imu/bmm150/bmm150.py b/micropython/drivers/imu/bmm150/bmm150.py index b7b4aad30..036b2b258 100644 --- a/micropython/drivers/imu/bmm150/bmm150.py +++ b/micropython/drivers/imu/bmm150/bmm150.py @@ -165,9 +165,6 @@ def _compensate_z(self, raw, hall): z = (z5 / (z4 * 4)) / 16 return z - def reset(self): - self._write_reg(_CMD, 0xB6) - def magnet_raw(self): for i in range(0, 10): self._read_reg_into(_DATA, self.scratch) From 2d16f210b96c48a598b3595ad55313c21deac06e Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 9 Aug 2023 18:52:15 +1000 Subject: [PATCH 2/8] lsm6dsox: Add missing time import. Driver calls time.sleep_ms() in one place. Found by Ruff checking F821. Signed-off-by: Angus Gratton --- micropython/drivers/imu/lsm6dsox/lsm6dsox.py | 1 + 1 file changed, 1 insertion(+) diff --git a/micropython/drivers/imu/lsm6dsox/lsm6dsox.py b/micropython/drivers/imu/lsm6dsox/lsm6dsox.py index 1e4267ae7..1952c5bb1 100644 --- a/micropython/drivers/imu/lsm6dsox/lsm6dsox.py +++ b/micropython/drivers/imu/lsm6dsox/lsm6dsox.py @@ -46,6 +46,7 @@ import array from micropython import const +import time _CTRL3_C = const(0x12) _CTRL1_XL = const(0x10) From 1f3002b53731de7658f98d74a4d4fe7d47eb7ac9 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 9 Aug 2023 18:52:50 +1000 Subject: [PATCH 3/8] wm8960: Add missing self reference for sample table. Found by Ruff checking F821. Signed-off-by: Angus Gratton --- micropython/drivers/codec/wm8960/wm8960.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/drivers/codec/wm8960/wm8960.py b/micropython/drivers/codec/wm8960/wm8960.py index 573fce5e9..dc0dd655d 100644 --- a/micropython/drivers/codec/wm8960/wm8960.py +++ b/micropython/drivers/codec/wm8960/wm8960.py @@ -683,7 +683,7 @@ def alc_mode(self, channel, mode=ALC_MODE): ) self.regs[_ALC3] = (_ALC_MODE_MASK, mode << _ALC_MODE_SHIFT) try: - rate = _alc_sample_rate_table[self.sample_rate] + rate = self._alc_sample_rate_table[self.sample_rate] except: rate = 0 self.regs[_ADDCTL3] = (_DACCTL3_ALCSR_MASK, rate) From 786c0ea895ffebdd7a40dd0d5ec1a0515edd4a25 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 9 Aug 2023 18:50:57 +1000 Subject: [PATCH 4/8] all: Add missing const imports Found by Ruff checking F821. Signed-off-by: Angus Gratton --- micropython/aiorepl/aiorepl.py | 1 + micropython/drivers/imu/lsm9ds1/lsm9ds1.py | 1 + micropython/drivers/sensor/lps22h/lps22h.py | 1 + micropython/mip/mip/__init__.py | 1 + micropython/net/webrepl/webrepl.py | 1 + 5 files changed, 5 insertions(+) diff --git a/micropython/aiorepl/aiorepl.py b/micropython/aiorepl/aiorepl.py index 8ebaef079..8b3ce4f8c 100644 --- a/micropython/aiorepl/aiorepl.py +++ b/micropython/aiorepl/aiorepl.py @@ -1,6 +1,7 @@ # MIT license; Copyright (c) 2022 Jim Mussared import micropython +from micropython import const import re import sys import time diff --git a/micropython/drivers/imu/lsm9ds1/lsm9ds1.py b/micropython/drivers/imu/lsm9ds1/lsm9ds1.py index 7123a574b..e3d46429d 100644 --- a/micropython/drivers/imu/lsm9ds1/lsm9ds1.py +++ b/micropython/drivers/imu/lsm9ds1/lsm9ds1.py @@ -44,6 +44,7 @@ time.sleep_ms(100) """ import array +from micropython import const _WHO_AM_I = const(0xF) diff --git a/micropython/drivers/sensor/lps22h/lps22h.py b/micropython/drivers/sensor/lps22h/lps22h.py index ca29efce2..1e7f4ec3e 100644 --- a/micropython/drivers/sensor/lps22h/lps22h.py +++ b/micropython/drivers/sensor/lps22h/lps22h.py @@ -38,6 +38,7 @@ time.sleep_ms(10) """ import machine +from micropython import const _LPS22_CTRL_REG1 = const(0x10) _LPS22_CTRL_REG2 = const(0x11) diff --git a/micropython/mip/mip/__init__.py b/micropython/mip/mip/__init__.py index 5f6f4fcd6..68daf32fe 100644 --- a/micropython/mip/mip/__init__.py +++ b/micropython/mip/mip/__init__.py @@ -1,6 +1,7 @@ # MicroPython package installer # MIT license; Copyright (c) 2022 Jim Mussared +from micropython import const import requests import sys diff --git a/micropython/net/webrepl/webrepl.py b/micropython/net/webrepl/webrepl.py index 56767d8b7..48c181968 100644 --- a/micropython/net/webrepl/webrepl.py +++ b/micropython/net/webrepl/webrepl.py @@ -1,6 +1,7 @@ # This module should be imported from REPL, not run from command line. import binascii import hashlib +from micropython import const import network import os import socket From c6a72c70b9bb516bdc9fd234b321b5b20ac7bf90 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 9 Aug 2023 18:53:18 +1000 Subject: [PATCH 5/8] cbor2: Improve decoder to pass Ruff F821 undefined-name. These were probably intentional missing names, however raising NotImplementedError or KeyError is more explicit than trying to call an unknown function. Signed-off-by: Angus Gratton --- python-ecosys/cbor2/cbor2/decoder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-ecosys/cbor2/cbor2/decoder.py b/python-ecosys/cbor2/cbor2/decoder.py index f0784d4be..48ff02d89 100644 --- a/python-ecosys/cbor2/cbor2/decoder.py +++ b/python-ecosys/cbor2/cbor2/decoder.py @@ -160,7 +160,7 @@ def decode_simple_value(decoder): def decode_float16(decoder): payload = decoder.read(2) - return unpack_float16(payload) + raise NotImplementedError # no float16 unpack function def decode_float32(decoder): @@ -185,7 +185,7 @@ def decode_float64(decoder): 20: lambda self: False, 21: lambda self: True, 22: lambda self: None, - 23: lambda self: undefined, + # 23 is undefined 24: decode_simple_value, 25: decode_float16, 26: decode_float32, From 991ac986fd45781f99e9de36fefdc5c4838b99f0 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 9 Aug 2023 18:54:20 +1000 Subject: [PATCH 6/8] iperf3: Pre-declare some variables set in the loop. This is a change just to make the linter happy, the code probably would have run OK without it. Found by Ruff checking F821. Signed-off-by: Angus Gratton --- python-ecosys/iperf3/iperf3.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python-ecosys/iperf3/iperf3.py b/python-ecosys/iperf3/iperf3.py index 62ee01683..a5c54445d 100644 --- a/python-ecosys/iperf3/iperf3.py +++ b/python-ecosys/iperf3/iperf3.py @@ -380,9 +380,11 @@ def client(host, udp=False, reverse=False, bandwidth=10 * 1024 * 1024): ticks_us_end = param["time"] * 1000000 poll = select.poll() poll.register(s_ctrl, select.POLLIN) + buf = None s_data = None start = None udp_packet_id = 0 + udp_last_send = None while True: for pollable in poll.poll(stats.max_dt_ms()): if pollable_is_sock(pollable, s_data): From b46306cc5a7ce9332407345025cba4afca6ca967 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 9 Aug 2023 18:54:57 +1000 Subject: [PATCH 7/8] uaiohttpclient: Fix missing name in unreachable example code. As-written this code is unreachable (return statement two line above), so this change is really just to make the linter happy. Found by Ruff checking F821. Signed-off-by: Angus Gratton --- micropython/uaiohttpclient/example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/uaiohttpclient/example.py b/micropython/uaiohttpclient/example.py index 4134c7ee7..5c03ee29f 100644 --- a/micropython/uaiohttpclient/example.py +++ b/micropython/uaiohttpclient/example.py @@ -9,7 +9,7 @@ def print_stream(resp): print((yield from resp.read())) return while True: - line = yield from reader.readline() + line = yield from resp.readline() if not line: break print(line.rstrip()) From 5b6fb2bc565315a0ce3470bf6b4bdbcd70b0df7a Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 9 Aug 2023 18:55:48 +1000 Subject: [PATCH 8/8] top: Enable Ruff linter to check undefined-name (F821). Also adds some global ignores for manifest files (which have implicit imports) and the multitests (which have the same). Other F821 fixes or accommodations are in the parent commits to this commit. Signed-off-by: Angus Gratton --- pyproject.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6828563c9..1aa9c1122 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,6 @@ ignore = [ "F403", "F405", "F541", - "F821", "F841", "ISC003", # micropython does not support implicit concatenation of f-strings "PIE810", # micropython does not support passing tuples to .startswith or .endswith @@ -91,3 +90,10 @@ max-statements = 166 [tool.ruff.per-file-ignores] "micropython/aiorepl/aiorepl.py" = ["PGH001"] + +# manifest.py files are evaluated with some global names pre-defined +"**/manifest.py" = ["F821"] +"ports/**/boards/manifest*.py" = ["F821"] + +# ble multitests are evaluated with some names pre-defined +"micropython/bluetooth/aioble/multitests/*" = ["F821"]