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

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
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

pyproject.toml

Lines changed: 2 additions & 0 deletions
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",

src/api/check.py

Lines changed: 10 additions & 10 deletions
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
# ----------------------------------------------------------------------

src/api/debug.py

Lines changed: 1 addition & 1 deletion
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

src/api/errmsg.py

Lines changed: 7 additions & 1 deletion
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

src/api/exception.py

Lines changed: 4 additions & 4 deletions
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

src/api/options.py

Lines changed: 6 additions & 1 deletion
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:

src/api/symboltable/symboltable.py

Lines changed: 10 additions & 12 deletions
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

src/api/utils.py

Lines changed: 2 additions & 2 deletions
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,

src/arch/z80/__init__.py

Lines changed: 1 addition & 2 deletions
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

0 commit comments

Comments
 (0)