Skip to content

Commit 6f9905f

Browse files
committed
feat: update code to meet new Ruff linting rules
RUF021 and RUF022 had to be disabled. The latter looks like it's bugged.
1 parent b883590 commit 6f9905f

39 files changed

+130
-121
lines changed

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111

1212
- repo: https://github.com/astral-sh/ruff-pre-commit
1313
# Ruff version.
14-
rev: v0.4.10
14+
rev: v0.9.4
1515
hooks:
1616
# Run the linter.
1717
- id: ruff

Diff for: pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ ignore = [
153153
"RUF005",
154154
"RUF012",
155155
"RUF013",
156+
"RUF021",
157+
"RUF022", # isort sorting style is not alphabetical and seems not natural either (despite the doc)
156158
"UP008",
157159
"UP015", # KEEP: redundant-open-modes
158160
"UP024",

Diff for: src/api/check.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414
from src.symbols.symbol_ import Symbol
1515
from src.symbols.type_ import Type
1616

17-
__all__ = [
18-
"check_type",
19-
"check_is_declared_explicit",
17+
__all__ = (
2018
"check_and_make_label",
21-
"check_type_is_explicit",
2219
"check_call_arguments",
20+
"check_is_declared_explicit",
2321
"check_pending_calls",
2422
"check_pending_labels",
25-
"is_number",
23+
"check_type",
24+
"check_type_is_explicit",
25+
"common_type",
2626
"is_const",
27-
"is_static",
28-
"is_string",
29-
"is_numeric",
3027
"is_dynamic",
3128
"is_null",
29+
"is_number",
30+
"is_numeric",
31+
"is_static",
32+
"is_string",
3233
"is_unsigned",
33-
"common_type",
34-
]
34+
)
3535

3636

3737
# ----------------------------------------------------------------------

Diff for: src/api/debug.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .config import OPTIONS
99

10-
__all__ = ["__DEBUG__", "__LINE__", "__FILE__"]
10+
__all__ = "__DEBUG__", "__FILE__", "__LINE__"
1111

1212
# --------------------- END OF GLOBAL FLAGS ---------------------
1313

Diff for: src/api/errmsg.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
from src.api.constants import CLASS
1616

1717
# Exports only these functions. Others
18-
__all__ = ["error", "is_valid_warning_code", "warning", "warning_not_used", "register_warning"]
18+
__all__ = (
19+
"error",
20+
"is_valid_warning_code",
21+
"register_warning",
22+
"warning",
23+
"warning_not_used",
24+
)
1925

2026

2127
WARNING_PREFIX: str = "" # will be prepended to warning messages

Diff for: src/api/exception.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
__all__ = [
1414
"Error",
15-
"InvalidOperatorError",
16-
"InvalidLoopError",
17-
"InvalidCONSTexpr",
18-
"InvalidBuiltinFunctionError",
1915
"InternalError",
16+
"InvalidBuiltinFunctionError",
17+
"InvalidCONSTexpr",
18+
"InvalidLoopError",
19+
"InvalidOperatorError",
2020
"TempAlreadyFreedError",
2121
]
2222

Diff for: src/api/options.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
from src.api.exception import Error
1616

17-
__all__: Final[tuple[str, ...]] = "Option", "Options", "ANYTYPE", "Action"
17+
__all__: Final[tuple[str, ...]] = (
18+
"ANYTYPE",
19+
"Action",
20+
"Option",
21+
"Options",
22+
)
1823

1924

2025
class ANYTYPE:

Diff for: src/api/symboltable/symboltable.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,10 @@ def declare_variable(self, id_: str, lineno: int, type_, default_value=None, cla
492492
if entry_.scope == SCOPE.parameter:
493493
syntax_error(
494494
lineno,
495-
f"Variable '{id_}' already declared as a parameter " f"at {entry_.filename}:{entry_.lineno}",
495+
f"Variable '{id_}' already declared as a parameter at {entry_.filename}:{entry_.lineno}",
496496
)
497497
else:
498-
syntax_error(lineno, f"Variable '{id_}' already declared at " f"{entry_.filename}:{entry_.lineno}")
498+
syntax_error(lineno, f"Variable '{id_}' already declared at {entry_.filename}:{entry_.lineno}")
499499
return None
500500

501501
if not self.check_class(id_, class_, lineno, scope=self.current_scope):
@@ -525,7 +525,7 @@ def declare_variable(self, id_: str, lineno: int, type_, default_value=None, cla
525525
if entry.type_ != type_:
526526
if not type_.implicit and entry.type_ is not None:
527527
syntax_error(
528-
lineno, "'%s' suffix is for type '%s' but it was " "declared as '%s'" % (id_, entry.type_, type_)
528+
lineno, "'%s' suffix is for type '%s' but it was declared as '%s'" % (id_, entry.type_, type_)
529529
)
530530
return None
531531

@@ -575,10 +575,10 @@ def declare_const(self, id_: str, lineno: int, type_, default_value):
575575
if entry.scope == SCOPE.parameter:
576576
syntax_error(
577577
lineno,
578-
"Constant '%s' already declared as a parameter " "at %s:%i" % (id_, entry.filename, entry.lineno),
578+
"Constant '%s' already declared as a parameter at %s:%i" % (id_, entry.filename, entry.lineno),
579579
)
580580
else:
581-
syntax_error(lineno, "Constant '%s' already declared at " "%s:%i" % (id_, entry.filename, entry.lineno))
581+
syntax_error(lineno, "Constant '%s' already declared at %s:%i" % (id_, entry.filename, entry.lineno))
582582
return None
583583

584584
entry = self.declare_variable(id_, lineno, type_, default_value, class_=CLASS.const)
@@ -600,7 +600,7 @@ def declare_label(self, id_: str, lineno: int) -> symbols.ID | None:
600600
entry = self.get_entry(id_)
601601
if entry is not None and entry.declared:
602602
if entry.is_line_number:
603-
syntax_error(lineno, "Duplicated line number '%s'. " "Previous was at %i" % (entry.name, entry.lineno))
603+
syntax_error(lineno, "Duplicated line number '%s'. Previous was at %i" % (entry.name, entry.lineno))
604604
else:
605605
syntax_error(lineno, "Label '%s' already declared at line %i" % (id_, entry.lineno))
606606
return None
@@ -680,23 +680,21 @@ def declare_array(self, id_: str, lineno: int, type_, bounds, default_value=None
680680
if not entry.declared:
681681
if entry.callable:
682682
syntax_error(
683-
lineno, "Array '%s' must be declared before use. " "First used at line %i" % (id_, entry.lineno)
683+
lineno, "Array '%s' must be declared before use. First used at line %i" % (id_, entry.lineno)
684684
)
685685
return None
686686
else:
687687
if entry.scope == SCOPE.parameter:
688-
syntax_error(
689-
lineno, "variable '%s' already declared as a " "parameter at line %i" % (id_, entry.lineno)
690-
)
688+
syntax_error(lineno, "variable '%s' already declared as a parameter at line %i" % (id_, entry.lineno))
691689
else:
692-
syntax_error(lineno, "variable '%s' already declared at " "line %i" % (id_, entry.lineno))
690+
syntax_error(lineno, "variable '%s' already declared at line %i" % (id_, entry.lineno))
693691
return None
694692

695693
if entry.type_ != self.basic_types[TYPE.unknown] and entry.type_ != type_:
696694
if not type_.implicit:
697695
syntax_error(
698696
lineno,
699-
"Array suffix for '%s' is for type '%s' " "but declared as '%s'" % (entry.name, entry.type_, type_),
697+
"Array suffix for '%s' is for type '%s' but declared as '%s'" % (entry.name, entry.type_, type_),
700698
)
701699
return None
702700

Diff for: src/api/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
from src.api import constants, errmsg, global_
1111

1212
__all__ = (
13+
"chdir",
14+
"first",
1315
"flatten_list",
1416
"open_file",
1517
"read_txt_file",
1618
"sanitize_filename",
1719
"timeout",
18-
"first",
19-
"chdir",
2020
)
2121

2222
__doc__ = """Utils module contains many helpers for several task,

Diff for: src/arch/z80/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
from .visitor.translator import Translator
99
from .visitor.var_translator import VarTranslator
1010

11-
__all__ = "beep", "FunctionTranslator", "Translator", "VarTranslator"
12-
11+
__all__ = "FunctionTranslator", "Translator", "VarTranslator", "beep"
1312

1413
# -----------------------------------------
1514
# Arch initialization setup

Diff for: src/arch/z80/backend/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
from .main import Backend
1818

1919
__all__ = (
20+
"Backend",
21+
"Bits8",
2022
"Bits16",
2123
"Float",
22-
"INITS",
2324
"HI16",
25+
"ICInfo",
26+
"INITS",
2427
"LO16",
2528
"MAIN_LABEL",
2629
"MEMINITS",
2730
"REQUIRES",
2831
"START_LABEL",
2932
"TMP_COUNTER",
3033
"TMP_STORAGES",
31-
"Backend",
3234
"engine",
33-
"ICInfo",
34-
"Bits8",
3535
)

Diff for: src/arch/z80/optimizer/asm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class Asm:
1414
"""Defines an asm instruction"""
1515

16-
__slots__ = "inst", "oper", "asm", "cond", "output", "_bytes", "_max_tstates", "is_label"
16+
__slots__ = "_bytes", "_max_tstates", "asm", "cond", "inst", "is_label", "oper", "output"
1717

1818
_operands_cache: dict[str, list[str]] = {}
1919

Diff for: src/arch/z80/optimizer/cpustate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def set(self, r: str, val: int | str | None) -> None:
411411
if is_unknown8(val):
412412
val = f"{new_tmp_val()}{HL_SEP}{val}"
413413
assert is_num or is_unknown16(val) or is_label(val), (
414-
f"val '{val}' is neither a number, nor a label" " nor an unknown16"
414+
f"val '{val}' is neither a number, nor a label nor an unknown16"
415415
)
416416

417417
self.regs[r] = val

Diff for: src/arch/z80/optimizer/helpers.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,38 @@
66
__all__ = (
77
"ALL_REGS",
88
"END_PROGRAM_LABEL",
9+
"HI16",
10+
"HI16_val",
11+
"LO16",
12+
"LO16_val",
13+
"dict_intersection",
14+
"get_H_from_unknown_value",
15+
"get_L_from_unknown_value",
16+
"get_orig_label_from_unknown16",
17+
"idx_args",
918
"init",
10-
"new_tmp_val",
11-
"new_tmp_val16",
12-
"new_tmp_val16_from_label",
19+
"is_8bit_idx_register",
20+
"is_8bit_normal_register",
21+
"is_8bit_oper_register",
22+
"is_16bit_composed_register",
23+
"is_16bit_idx_register",
24+
"is_16bit_normal_register",
25+
"is_16bit_oper_register",
26+
"is_label",
27+
"is_mem_access",
28+
"is_number",
29+
"is_register",
1330
"is_unknown",
1431
"is_unknown8",
1532
"is_unknown16",
16-
"get_orig_label_from_unknown16",
17-
"get_L_from_unknown_value",
18-
"get_H_from_unknown_value",
19-
"is_mem_access",
20-
"is_number",
21-
"is_label",
22-
"valnum",
23-
"to_int",
33+
"new_tmp_val",
34+
"new_tmp_val16",
35+
"new_tmp_val16_from_label",
2436
"simplify_arg",
2537
"simplify_asm_args",
26-
"is_register",
27-
"is_8bit_normal_register",
28-
"is_8bit_idx_register",
29-
"is_8bit_oper_register",
30-
"is_16bit_normal_register",
31-
"is_16bit_idx_register",
32-
"is_16bit_composed_register",
33-
"is_16bit_oper_register",
34-
"LO16",
35-
"HI16",
3638
"single_registers",
37-
"idx_args",
38-
"LO16_val",
39-
"HI16_val",
40-
"dict_intersection",
39+
"to_int",
40+
"valnum",
4141
)
4242

4343

Diff for: src/arch/z80/optimizer/memcell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MemCell:
1414
the instruction.
1515
"""
1616

17-
__slots__ = "addr", "__instr", "__dict__"
17+
__slots__ = "__dict__", "__instr", "addr"
1818
__instr: Asm
1919

2020
def __init__(self, instr: str, addr: int):

Diff for: src/arch/z80/peephole/evaluator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class Evaluator:
164164
+ (addition or concatenation for strings)
165165
"""
166166

167-
__slots__ = "str_", "expression"
167+
__slots__ = "expression", "str_"
168168

169169
def __init__(self, expression):
170170
"""Initializes the object parsing the expression and preparing it for its (later)

Diff for: src/arch/z80/peephole/pattern.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class BasicLinePattern:
1010
$1 a pattern variable
1111
"""
1212

13-
__slots__ = "line", "vars", "re_pattern", "re", "output"
13+
__slots__ = "line", "output", "re", "re_pattern", "vars"
1414

1515
@staticmethod
1616
def sanitize(pattern):
@@ -68,7 +68,7 @@ class LinePattern(BasicLinePattern):
6868
If it matched, the vars_ dictionary will be updated with unified vars.
6969
"""
7070

71-
__slots__ = "line", "vars", "re_pattern", "re", "output"
71+
__slots__ = "line", "output", "re", "re_pattern", "vars"
7272

7373
def match(self, line: str, vars_: dict[str, str]) -> bool:
7474
match = self.re.match(line)

Diff for: src/arch/zx48k/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
)
1212
from src.arch.zx48k import backend # noqa
1313

14-
__all__ = [
15-
"beep",
16-
"VarTranslator",
14+
__all__ = (
1715
"FunctionTranslator",
1816
"Translator",
19-
]
17+
"VarTranslator",
18+
"beep",
19+
)
2020

2121

2222
# -----------------------------------------

Diff for: src/arch/zx48k/backend/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from src.arch.z80.backend import Backend as Z80Backend
1313

1414
__all__ = (
15-
"Float",
1615
"HI16",
1716
"INITS",
1817
"LO16",
@@ -21,6 +20,7 @@
2120
"TMP_COUNTER",
2221
"TMP_STORAGES",
2322
"Backend",
23+
"Float",
2424
)
2525

2626

Diff for: src/arch/zxnext/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
optimizer, # noqa
99
)
1010

11-
__all__ = "beep", "VarTranslator", "FunctionTranslator", "Translator"
11+
__all__ = (
12+
"FunctionTranslator",
13+
"Translator",
14+
"VarTranslator",
15+
"beep",
16+
)
1217

1318

1419
# -----------------------------------------

0 commit comments

Comments
 (0)