Skip to content

all: Upgrade to ruff v0.9.6. #16774

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

Merged
merged 1 commit into from
Feb 25, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
steps:
- uses: actions/checkout@v4
# ruff version should be kept in sync with .pre-commit-config.yaml
- run: pip install --user ruff==0.1.3
- run: pipx install ruff==0.9.6
- run: ruff check --output-format=github .
- run: ruff format --diff .
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
stages: [commit-msg]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Version should be kept in sync with .github/workflows/ruff.yml
rev: v0.1.3
rev: v0.9.6
hooks:
- id: ruff
- id: ruff-format
Expand Down
1 change: 1 addition & 0 deletions ports/nrf/examples/seeed_tft.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
tf = mount_tf()
os.listdir()
"""

import vfs
import time
import framebuf
Expand Down
22 changes: 16 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ line-length = 99
target-version = "py37"

[tool.ruff.lint]
exclude = [ # Ruff finds Python SyntaxError in these files
"tests/cmdline/repl_autocomplete.py",
"tests/cmdline/repl_autoindent.py",
"tests/cmdline/repl_basic.py",
"tests/cmdline/repl_cont.py",
"tests/cmdline/repl_emacs_keys.py",
"tests/cmdline/repl_words_move.py",
"tests/feature_check/repl_emacs_check.py",
"tests/feature_check/repl_words_move_check.py",
"tests/micropython/viper_args.py",
]
extend-select = ["C9", "PLC"]
ignore = [
"E401",
Expand All @@ -37,14 +48,12 @@ ignore = [
"F401",
"F403",
"F405",
"PLC1901",
"PLC0206",
]
mccabe.max-complexity = 40

[tool.ruff.mccabe]
max-complexity = 40

[tool.ruff.per-file-ignores]
# Exclude all tests from linting (does not apply to formatting).
[tool.ruff.lint.per-file-ignores]
# Exclude all tests from linting.
"tests/**/*.py" = ["ALL"]
"ports/cc3200/tools/uniflash.py" = ["E711"]
# manifest.py files are evaluated with some global names pre-defined
Expand All @@ -57,3 +66,4 @@ max-complexity = 40
# repl_: not real python files
# viper_args: uses f(*)
exclude = ["tests/basics/*.py", "tests/*/repl_*.py", "tests/micropython/viper_args.py"]
quote-style = "preserve"
1 change: 1 addition & 0 deletions tests/cpydiff/builtin_next_arg2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
except StopIteration:
val = deflt
"""

print(next(iter(range(0)), 42))
1 change: 1 addition & 0 deletions tests/cpydiff/core_class_delnotimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

import gc


Expand Down
2 changes: 2 additions & 0 deletions tests/cpydiff/core_fstring_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"""

x, y = 1, 2
# fmt: off
print("aa" f"{x}") # works
print(f"{x}" "ab") # works
print("a{}a" f"{x}") # fails
print(f"{x}" "a{}b") # fails
# fmt: on
1 change: 1 addition & 0 deletions tests/cpydiff/core_function_argcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: MicroPython counts "self" as an argument.
workaround: Interpret error messages with the information above in mind.
"""

try:
[].append()
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/core_import_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Not implemented.
workaround: Manually import the sub-modules directly in __init__.py using ``from . import foo, bar``.
"""

from modules3 import *

foo.hello()
1 change: 1 addition & 0 deletions tests/cpydiff/core_import_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: MicroPython doesn't support namespace packages split across filesystem. Beyond that, MicroPython's import system is highly optimized for minimal memory usage.
workaround: Details of import handling is inherently implementation dependent. Don't rely on such details in portable applications.
"""

import modules

print(modules.__path__)
1 change: 1 addition & 0 deletions tests/cpydiff/core_import_split_ns_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: MicroPython's import system is highly optimized for simplicity, minimal memory usage, and minimal filesystem search overhead.
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).
"""

import sys

sys.path.append(sys.path[1] + "/modules")
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/core_locals_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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())``.
workaround: Unknown
"""

val = 1


Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/module_array_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Code size
workaround: Compare individual elements
"""

import array

array.array("b", [1, 2]) == array.array("i", [1, 2])
1 change: 1 addition & 0 deletions tests/cpydiff/module_array_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: MicroPython implements implicit truncation in order to reduce code size and execution time
workaround: If CPython compatibility is needed then mask the value explicitly
"""

import array

a = array.array("b", [257])
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/modules_array_containment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

import array

print(1 in array.array("B", b"12"))
1 change: 1 addition & 0 deletions tests/cpydiff/modules_array_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

import array

a = array.array("b", (1, 2, 3))
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/modules_array_subscrstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

import array

a = array.array("b", (1, 2, 3))
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/modules_json_nonserializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

import json

try:
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/modules_os_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Use ``getenv``, ``putenv`` and ``unsetenv``
"""

import os

try:
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/modules_os_getenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: The ``environ`` attribute is not implemented
workaround: Unknown
"""

import os

print(os.getenv("NEW_VARIABLE"))
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/modules_struct_fewargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

import struct

try:
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/modules_struct_manyargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

import struct

try:
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/modules_struct_whitespace_in_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: MicroPython is optimised for code size.
workaround: Don't use spaces in format strings.
"""

import struct

try:
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/modules_sys_stdassign.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: They are stored in read-only memory.
workaround: Unknown
"""

import sys

sys.stdin = None
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/syntax_assign_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: MicroPython is optimised for code size and doesn't check this case.
workaround: Do not rely on this behaviour if writing CPython compatible code.
"""

print([i := -1 for i in range(4)])
1 change: 1 addition & 0 deletions tests/cpydiff/syntax_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

try:
print(eval("1and 0"))
except SyntaxError:
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/syntax_unicode_nameesc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Unknown
workaround: Unknown
"""

print("\N{LATIN SMALL LETTER A}")
1 change: 1 addition & 0 deletions tests/cpydiff/types_bytearray_sliceassign.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

b = bytearray(4)
b[0:1] = [1, 2]
print(b)
1 change: 1 addition & 0 deletions tests/cpydiff/types_bytes_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
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.
workaround: If you are interested in CPython compatibility, don't use ``.format()`` on bytes objects.
"""

print(b"{}".format(1))
1 change: 1 addition & 0 deletions tests/cpydiff/types_bytes_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Unknown
workaround: Pass the encoding as a positional parameter, e.g. ``print(bytes('abc', 'utf-8'))``
"""

print(bytes("abc", encoding="utf8"))
1 change: 1 addition & 0 deletions tests/cpydiff/types_bytes_subscrstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: MicroPython is highly optimized for memory usage.
workaround: Use explicit loop for this very rare operation.
"""

print(b"123"[0:3:2])
1 change: 1 addition & 0 deletions tests/cpydiff/types_dict_keys_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Not implemented.
workaround: Explicitly convert keys to a set before using set operations.
"""

print({1: 2, 3: 4}.keys() & {1})
1 change: 1 addition & 0 deletions tests/cpydiff/types_exception_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: MicroPython is optimised to reduce code size.
workaround: Only use ``value`` on ``StopIteration`` exceptions, and ``errno`` on ``OSError`` exceptions. Do not use or rely on these attributes on other exceptions.
"""

e = Exception(1)
print(e.value)
print(e.errno)
1 change: 1 addition & 0 deletions tests/cpydiff/types_exception_chaining.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Unknown
"""

try:
raise TypeError
except TypeError:
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/types_exception_instancevar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: MicroPython is highly optimized for memory usage.
workaround: Use user-defined exception subclasses.
"""

e = Exception()
e.x = 0
print(e.x)
1 change: 1 addition & 0 deletions tests/cpydiff/types_exception_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Condition checks are optimized to happen at the end of loop body, and that line number is reported.
workaround: Unknown
"""

l = ["-foo", "-bar"]

i = 0
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/types_float_rounding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Unknown
workaround: Unknown
"""

print("%.1g" % -9.9)
1 change: 1 addition & 0 deletions tests/cpydiff/types_list_delete_subscrstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Use explicit loop for this rare operation.
"""

l = [1, 2, 3, 4]
del l[0:4:2]
print(l)
1 change: 1 addition & 0 deletions tests/cpydiff/types_list_store_noniter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: RHS is restricted to be a tuple or list
workaround: Use ``list(<iter>)`` on RHS to convert the iterable to a list
"""

l = [10, 20]
l[0:1] = range(4)
print(l)
1 change: 1 addition & 0 deletions tests/cpydiff/types_list_store_subscrstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
cause: Unknown
workaround: Use explicit loop for this rare operation.
"""

l = [1, 2, 3, 4]
l[0:4:2] = [5, 6]
print(l)
1 change: 1 addition & 0 deletions tests/cpydiff/types_memoryview_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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.
workaround: Do not change the size of any ``bytearray`` or ``io.bytesIO`` object that has a ``memoryview`` assigned to it.
"""

b = bytearray(b"abcdefg")
m = memoryview(b)
b.extend(b"hijklmnop")
Expand Down
1 change: 1 addition & 0 deletions tests/cpydiff/types_str_endswith.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Unknown
workaround: Unknown
"""

print("abc".endswith("c", 1))
1 change: 1 addition & 0 deletions tests/cpydiff/types_str_formatsubscr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Unknown
workaround: Unknown
"""

print("{a[0]}".format(a=[1, 2]))
1 change: 1 addition & 0 deletions tests/cpydiff/types_str_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Unknown
workaround: Input the encoding format directly. eg ``print(bytes('abc', 'utf-8'))``
"""

print(str(b"abc", encoding="utf8"))
1 change: 1 addition & 0 deletions tests/cpydiff/types_str_ljust_rjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: MicroPython is highly optimized for memory usage. Easy workarounds available.
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)``.
"""

print("abc".ljust(10))
1 change: 1 addition & 0 deletions tests/cpydiff/types_str_rsplitnone.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Unknown
workaround: Unknown
"""

print("a a a".rsplit(None, 1))
1 change: 1 addition & 0 deletions tests/cpydiff/types_str_subscrstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Unknown
workaround: Unknown
"""

print("abcdefghi"[0:9:2])
1 change: 1 addition & 0 deletions tests/cpydiff/types_tuple_subscrstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
cause: Unknown
workaround: Unknown
"""

print((1, 2, 3, 4)[0:4:2])
1 change: 1 addition & 0 deletions tests/ports/cc3200/pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pull up or pull down connected.
GP12 and GP17 must be connected together
"""

from machine import Pin
import os

Expand Down
Loading
Loading