-
Notifications
You must be signed in to change notification settings - Fork 1k
all: Lint Python code with ruff. #651
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
Conversation
68a761f
to
99806b5
Compare
Thanks for working on this! |
de6a771
to
8d4b1ba
Compare
Thanks for the reminder. I rebased and squashed the changes. But looks like ruff was updated in the meantime and now has more warnings? Note that some of the suggestions go against MicroPython best practice, eg because they allocate memory. |
5e09c3d
to
0ea0a9b
Compare
OK... Rebased. I do not see any memory allocations but please let me know if you do. |
@@ -149,7 +149,7 @@ def send(self, sensor_data, adjust_output_power=True): | |||
delta = time.ticks_diff(maybe_ack.ticks_ms, sent_at) | |||
print( | |||
f"ACKed with RSSI {rssi}, {delta}ms after sent " | |||
+ f"(skew {delta-ACK_DELAY_MS-ack_packet_ms}ms)" | |||
f"(skew {delta-ACK_DELAY_MS-ack_packet_ms}ms)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MicroPython doesn't support adjacent f-strings, it needs the "+".
(This file is not tested by the CI here, because it's an example.)
@@ -141,7 +141,7 @@ async def send(self, sensor_data, adjust_output_power=True): | |||
delta = time.ticks_diff(maybe_ack.ticks_ms, sent_at) | |||
print( | |||
f"ACKed with RSSI {rssi}, {delta}ms after sent " | |||
+ f"(skew {delta-ACK_DELAY_MS-ack_packet_ms}ms)" | |||
f"(skew {delta-ACK_DELAY_MS-ack_packet_ms}ms)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "+" is needed.
@@ -183,7 +183,7 @@ def main(): | |||
(sf, bw_khz, coding_rate, low_datarate_optimize) = modem_settings | |||
print( | |||
f"Modem config sf={sf} bw={bw_khz}kHz coding_rate=4/{coding_rate} " | |||
+ f"low_datarate_optimize={low_datarate_optimize}" | |||
f"low_datarate_optimize={low_datarate_optimize}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "+" is needed.
Signed-off-by: Christian Clauss <cclauss@me.com>
Ignore explicit-string-concatenation (ISC003)Derived from the flake8-implicit-str-concat linter. What it doesChecks for string literals that are explicitly concatenated (using the Why is this bad?For string literals that wrap across multiple lines, implicit string concatenation within parentheses is preferred over explicit concatenation using the Examplez = (
"The quick brown fox jumps over the lazy "
+ "dog"
) Use instead: z = (
"The quick brown fox jumps over the lazy "
"dog"
) |
Thank you, looks pretty good now! |
As hinted at micropython/micropython#10977 (comment)
Ruff supports over 500 lint rules and can be used to replace Flake8 (plus dozens of plugins), isort, pydocstyle, yesqa, eradicate, pyupgrade, and autoflake, all while executing (in Rust) tens or hundreds of times faster than any individual tool.
The ruff Action uses minimal steps to run in ~5 seconds, rapidly providing intuitive GitHub Annotations to contributors.