Skip to content

Commit dc2fcfc

Browse files
committed
all: Upgrade to ruff v0.9.6.
Signed-off-by: Christian Clauss <[email protected]>
1 parent 3f0dd13 commit dc2fcfc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+73
-17
lines changed

.github/workflows/ruff.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ jobs:
88
steps:
99
- uses: actions/checkout@v4
1010
# ruff version should be kept in sync with .pre-commit-config.yaml
11-
- run: pip install --user ruff==0.1.3
11+
- run: pipx install ruff==0.9.6
1212
- run: ruff check --output-format=github .
1313
- run: ruff format --diff .

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
stages: [commit-msg]
1414
- repo: https://github.com/charliermarsh/ruff-pre-commit
1515
# Version should be kept in sync with .github/workflows/ruff.yml
16-
rev: v0.1.3
16+
rev: v0.9.6
1717
hooks:
1818
- id: ruff
1919
- id: ruff-format

ports/nrf/examples/seeed_tft.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
tf = mount_tf()
4545
os.listdir()
4646
"""
47+
4748
import vfs
4849
import time
4950
import framebuf

pyproject.toml

+16-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ line-length = 99
2727
target-version = "py37"
2828

2929
[tool.ruff.lint]
30+
exclude = [ # Ruff finds Python SyntaxError in these files
31+
"tests/cmdline/repl_autocomplete.py",
32+
"tests/cmdline/repl_autoindent.py",
33+
"tests/cmdline/repl_basic.py",
34+
"tests/cmdline/repl_cont.py",
35+
"tests/cmdline/repl_emacs_keys.py",
36+
"tests/cmdline/repl_words_move.py",
37+
"tests/feature_check/repl_emacs_check.py",
38+
"tests/feature_check/repl_words_move_check.py",
39+
"tests/micropython/viper_args.py",
40+
]
3041
extend-select = ["C9", "PLC"]
3142
ignore = [
3243
"E401",
@@ -37,14 +48,12 @@ ignore = [
3748
"F401",
3849
"F403",
3950
"F405",
40-
"PLC1901",
51+
"PLC0206",
4152
]
53+
mccabe.max-complexity = 40
4254

43-
[tool.ruff.mccabe]
44-
max-complexity = 40
45-
46-
[tool.ruff.per-file-ignores]
47-
# Exclude all tests from linting (does not apply to formatting).
55+
[tool.ruff.lint.per-file-ignores]
56+
# Exclude all tests from linting.
4857
"tests/**/*.py" = ["ALL"]
4958
"ports/cc3200/tools/uniflash.py" = ["E711"]
5059
# manifest.py files are evaluated with some global names pre-defined
@@ -57,3 +66,4 @@ max-complexity = 40
5766
# repl_: not real python files
5867
# viper_args: uses f(*)
5968
exclude = ["tests/basics/*.py", "tests/*/repl_*.py", "tests/micropython/viper_args.py"]
69+
quote-style = "preserve"

tests/cpydiff/builtin_next_arg2.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
except StopIteration:
1010
val = deflt
1111
"""
12+
1213
print(next(iter(range(0)), 42))

tests/cpydiff/core_class_delnotimpl.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
import gc
89

910

tests/cpydiff/core_fstring_concat.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"""
77

88
x, y = 1, 2
9+
# fmt: off
910
print("aa" f"{x}") # works
1011
print(f"{x}" "ab") # works
1112
print("a{}a" f"{x}") # fails
1213
print(f"{x}" "a{}b") # fails
14+
# fmt: on

tests/cpydiff/core_function_argcount.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: MicroPython counts "self" as an argument.
55
workaround: Interpret error messages with the information above in mind.
66
"""
7+
78
try:
89
[].append()
910
except Exception as e:

tests/cpydiff/core_import_all.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Not implemented.
55
workaround: Manually import the sub-modules directly in __init__.py using ``from . import foo, bar``.
66
"""
7+
78
from modules3 import *
89

910
foo.hello()

tests/cpydiff/core_import_path.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: MicroPython doesn't support namespace packages split across filesystem. Beyond that, MicroPython's import system is highly optimized for minimal memory usage.
55
workaround: Details of import handling is inherently implementation dependent. Don't rely on such details in portable applications.
66
"""
7+
78
import modules
89

910
print(modules.__path__)

tests/cpydiff/core_import_split_ns_pkgs.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: MicroPython's import system is highly optimized for simplicity, minimal memory usage, and minimal filesystem search overhead.
55
workaround: Don't install modules belonging to the same namespace package in different directories. For MicroPython, it's recommended to have at most 3-component module search paths: for your current application, per-user (writable), system-wide (non-writable).
66
"""
7+
78
import sys
89

910
sys.path.append(sys.path[1] + "/modules")

tests/cpydiff/core_locals_eval.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name. Effectively, ``eval(expr)`` in MicroPython is equivalent to ``eval(expr, globals(), globals())``.
55
workaround: Unknown
66
"""
7+
78
val = 1
89

910

tests/cpydiff/module_array_comparison.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Code size
55
workaround: Compare individual elements
66
"""
7+
78
import array
89

910
array.array("b", [1, 2]) == array.array("i", [1, 2])

tests/cpydiff/module_array_constructor.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: MicroPython implements implicit truncation in order to reduce code size and execution time
55
workaround: If CPython compatibility is needed then mask the value explicitly
66
"""
7+
78
import array
89

910
a = array.array("b", [257])

tests/cpydiff/modules_array_containment.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
import array
89

910
print(1 in array.array("B", b"12"))

tests/cpydiff/modules_array_deletion.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
import array
89

910
a = array.array("b", (1, 2, 3))

tests/cpydiff/modules_array_subscrstep.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
import array
89

910
a = array.array("b", (1, 2, 3))

tests/cpydiff/modules_json_nonserializable.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
import json
89

910
try:

tests/cpydiff/modules_os_environ.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Use ``getenv``, ``putenv`` and ``unsetenv``
66
"""
7+
78
import os
89

910
try:

tests/cpydiff/modules_os_getenv.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: The ``environ`` attribute is not implemented
55
workaround: Unknown
66
"""
7+
78
import os
89

910
print(os.getenv("NEW_VARIABLE"))

tests/cpydiff/modules_struct_fewargs.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
import struct
89

910
try:

tests/cpydiff/modules_struct_manyargs.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
import struct
89

910
try:

tests/cpydiff/modules_struct_whitespace_in_format.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: MicroPython is optimised for code size.
55
workaround: Don't use spaces in format strings.
66
"""
7+
78
import struct
89

910
try:

tests/cpydiff/modules_sys_stdassign.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: They are stored in read-only memory.
55
workaround: Unknown
66
"""
7+
78
import sys
89

910
sys.stdin = None

tests/cpydiff/syntax_assign_expr.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: MicroPython is optimised for code size and doesn't check this case.
55
workaround: Do not rely on this behaviour if writing CPython compatible code.
66
"""
7+
78
print([i := -1 for i in range(4)])

tests/cpydiff/syntax_spaces.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
try:
89
print(eval("1and 0"))
910
except SyntaxError:

tests/cpydiff/syntax_unicode_nameesc.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
print("\N{LATIN SMALL LETTER A}")

tests/cpydiff/types_bytearray_sliceassign.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
b = bytearray(4)
89
b[0:1] = [1, 2]
910
print(b)

tests/cpydiff/types_bytes_format.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: MicroPython strives to be a more regular implementation, so if both `str` and `bytes` support ``__mod__()`` (the % operator), it makes sense to support ``format()`` for both too. Support for ``__mod__`` can also be compiled out, which leaves only ``format()`` for bytes formatting.
55
workaround: If you are interested in CPython compatibility, don't use ``.format()`` on bytes objects.
66
"""
7+
78
print(b"{}".format(1))

tests/cpydiff/types_bytes_keywords.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Unknown
55
workaround: Pass the encoding as a positional parameter, e.g. ``print(bytes('abc', 'utf-8'))``
66
"""
7+
78
print(bytes("abc", encoding="utf8"))

tests/cpydiff/types_bytes_subscrstep.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: MicroPython is highly optimized for memory usage.
55
workaround: Use explicit loop for this very rare operation.
66
"""
7+
78
print(b"123"[0:3:2])

tests/cpydiff/types_dict_keys_set.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Not implemented.
55
workaround: Explicitly convert keys to a set before using set operations.
66
"""
7+
78
print({1: 2, 3: 4}.keys() & {1})

tests/cpydiff/types_exception_attrs.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: MicroPython is optimised to reduce code size.
55
workaround: Only use ``value`` on ``StopIteration`` exceptions, and ``errno`` on ``OSError`` exceptions. Do not use or rely on these attributes on other exceptions.
66
"""
7+
78
e = Exception(1)
89
print(e.value)
910
print(e.errno)

tests/cpydiff/types_exception_chaining.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
try:
89
raise TypeError
910
except TypeError:

tests/cpydiff/types_exception_instancevar.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: MicroPython is highly optimized for memory usage.
55
workaround: Use user-defined exception subclasses.
66
"""
7+
78
e = Exception()
89
e.x = 0
910
print(e.x)

tests/cpydiff/types_exception_loops.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Condition checks are optimized to happen at the end of loop body, and that line number is reported.
55
workaround: Unknown
66
"""
7+
78
l = ["-foo", "-bar"]
89

910
i = 0

tests/cpydiff/types_float_rounding.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
print("%.1g" % -9.9)

tests/cpydiff/types_list_delete_subscrstep.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Use explicit loop for this rare operation.
66
"""
7+
78
l = [1, 2, 3, 4]
89
del l[0:4:2]
910
print(l)

tests/cpydiff/types_list_store_noniter.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: RHS is restricted to be a tuple or list
55
workaround: Use ``list(<iter>)`` on RHS to convert the iterable to a list
66
"""
7+
78
l = [10, 20]
89
l[0:1] = range(4)
910
print(l)

tests/cpydiff/types_list_store_subscrstep.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cause: Unknown
55
workaround: Use explicit loop for this rare operation.
66
"""
7+
78
l = [1, 2, 3, 4]
89
l[0:4:2] = [5, 6]
910
print(l)

tests/cpydiff/types_memoryview_invalid.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
In the worst case scenario, resizing an object which is the target of a memoryview can cause the memoryview(s) to reference invalid freed memory (a use-after-free bug) and corrupt the MicroPython runtime.
77
workaround: Do not change the size of any ``bytearray`` or ``io.bytesIO`` object that has a ``memoryview`` assigned to it.
88
"""
9+
910
b = bytearray(b"abcdefg")
1011
m = memoryview(b)
1112
b.extend(b"hijklmnop")

tests/cpydiff/types_str_endswith.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
print("abc".endswith("c", 1))

tests/cpydiff/types_str_formatsubscr.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
print("{a[0]}".format(a=[1, 2]))

tests/cpydiff/types_str_keywords.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Unknown
55
workaround: Input the encoding format directly. eg ``print(bytes('abc', 'utf-8'))``
66
"""
7+
78
print(str(b"abc", encoding="utf8"))

tests/cpydiff/types_str_ljust_rjust.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: MicroPython is highly optimized for memory usage. Easy workarounds available.
55
workaround: Instead of ``s.ljust(10)`` use ``"%-10s" % s``, instead of ``s.rjust(10)`` use ``"% 10s" % s``. Alternatively, ``"{:<10}".format(s)`` or ``"{:>10}".format(s)``.
66
"""
7+
78
print("abc".ljust(10))

tests/cpydiff/types_str_rsplitnone.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
print("a a a".rsplit(None, 1))

tests/cpydiff/types_str_subscrstep.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
print("abcdefghi"[0:9:2])

tests/cpydiff/types_tuple_subscrstep.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
cause: Unknown
55
workaround: Unknown
66
"""
7+
78
print((1, 2, 3, 4)[0:4:2])

tests/ports/cc3200/pin.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pull up or pull down connected.
44
GP12 and GP17 must be connected together
55
"""
6+
67
from machine import Pin
78
import os
89

0 commit comments

Comments
 (0)