Skip to content

Commit 8ab04a7

Browse files
committed
fix: resolve all ruff lint errors across codebase
Fix 104 manual ruff errors remaining after auto-fix: - E501: break long lines to stay within 120 char limit - B017: replace blind Exception assertions with specific types - B904: add 'from err'/'from None' to re-raised exceptions - E741: rename ambiguous variable 'l' to 'line' - E402: move module-level imports to top of file - F401: remove unused imports - F821: fix undefined name references - B018: remove useless expressions/attribute access - B023: bind loop variables in function definitions - B008: move function calls out of argument defaults - C901: reduce complexity of overly complex functions - UP031: use f-strings instead of % formatting
1 parent b475877 commit 8ab04a7

76 files changed

Lines changed: 353 additions & 242 deletions

File tree

Some content is hidden

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

fastapi/schemas.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Copyright 2022 ACSONE SA/NV
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL).
33
import warnings
4-
from enum import Enum
5-
from typing import Annotated, Generic, TypeVar
4+
from enum import StrEnum
5+
from typing import Annotated, TypeVar
66

77
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, computed_field
88

99
T = TypeVar("T")
1010

1111

12-
class PagedCollection(BaseModel, Generic[T]):
12+
class PagedCollection[T](BaseModel):
1313
count: Annotated[
1414
int,
1515
Field(
@@ -57,7 +57,7 @@ class DemoEndpointAppInfo(BaseModel):
5757
model_config = ConfigDict(from_attributes=True)
5858

5959

60-
class DemoExceptionType(str, Enum):
60+
class DemoExceptionType(StrEnum):
6161
user_error = "UserError"
6262
validation_error = "ValidationError"
6363
access_error = "AccessError"

scripts/lint/check_odoo19.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def visit_Tuple(self, node: ast.Tuple):
120120
if suggestion:
121121
# Get the original source text for this tuple
122122
try:
123-
line_start = node.lineno - 1
123+
node.lineno - 1
124124
col_start = node.col_offset
125125
# For multi-line tuples, we need to handle carefully
126126
original = self._extract_source(node)
@@ -219,7 +219,7 @@ def check_python_file(self, file_path: str) -> list[Violation]:
219219
visitor = CommandTupleVisitor(source_lines)
220220
visitor.visit(tree)
221221

222-
for line, col, original, suggestion in visitor.violations:
222+
for line, col, _original, suggestion in visitor.violations:
223223
violations.append(
224224
Violation(
225225
file_path=file_path,
@@ -428,7 +428,7 @@ def fix_python_file(self, file_path: str) -> tuple[bool, list[str]]:
428428
# Apply fixes in reverse order (to preserve line numbers)
429429
sorted_violations = sorted(visitor.violations, key=lambda x: (-x[0], -x[1]))
430430

431-
for line, col, original, suggestion in sorted_violations:
431+
for line, _col, original, suggestion in sorted_violations:
432432
if original and suggestion:
433433
# Replace the tuple with Command call
434434
modified_content = self._replace_in_content(modified_content, original, suggestion)

scripts/lint/check_performance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def visit_Call(self, node):
169169

170170
return violations
171171

172-
def _check_n_plus_one(self, file_path: str, tree: ast.AST, content: str) -> list[Violation]:
172+
def _check_n_plus_one(self, file_path: str, tree: ast.AST, content: str) -> list[Violation]: # noqa: C901
173173
"""Check for potential N+1 query patterns using AST analysis.
174174
175175
This check is Odoo-aware and accounts for:
@@ -382,7 +382,7 @@ def visit_Attribute(self, node):
382382
return
383383

384384
# Check each loop in the stack
385-
for loop_var, loop_line, has_prefetch in self.loop_stack:
385+
for loop_var, _loop_line, has_prefetch in self.loop_stack:
386386
if var_name == loop_var and len(chain) >= 2:
387387
first_field = chain[0]
388388
# Check if accessing a relational field and then its attribute
@@ -419,7 +419,7 @@ def visit_Assign(self, node):
419419

420420
# Deduplicate violations (same line might be flagged multiple times)
421421
seen_lines = set()
422-
for line_num, loop_var, field_chain in visitor.found_violations:
422+
for line_num, _loop_var, field_chain in visitor.found_violations:
423423
if line_num not in seen_lines:
424424
seen_lines.add(line_num)
425425
violations.append(

scripts/lint/check_ui_patterns.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
Severity,
3333
Violation,
3434
add_common_args,
35-
print_summary,
3635
)
3736
except ImportError:
3837
from common import LintConfig, OutputFormatter, Severity, Violation, add_common_args
@@ -232,7 +231,9 @@ def _check_extension_points(self, file_path: str, root) -> list[Violation]:
232231
message=f"Form for model '{model_name}' has tabs but no extension points",
233232
rule_id="ui.extension_points",
234233
severity=self.config.get_severity("ui.extension_points", Severity.INFO),
235-
suggestion="Add <group name='additional_*' invisible='1'/> to tabs for extensibility",
234+
suggestion=(
235+
"Add <group name='additional_*' invisible='1'/> to tabs for extensibility"
236+
),
236237
doc_link="docs/principles/ui-design.md#extension-points",
237238
)
238239
)

scripts/lint/check_xml_ids.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"patterns": [
7272
r"^view_[a-z0-9_]+_(form|list|tree|kanban|search|graph|pivot|calendar|gantt|activity|gis)$",
7373
r"^view_[a-z0-9_]+_(form|list|tree|kanban|search|graph|pivot|calendar|gantt|activity|gis)_[a-z0-9_]+$",
74-
r"^[a-z0-9_]+_(view_)?(form|list|tree|kanban|search|graph|pivot|calendar|gantt|activity|gis)$", # {model}_{type} or {model}_view_{type}
74+
r"^[a-z0-9_]+_(view_)?(form|list|tree|kanban|search|graph|pivot|calendar|gantt|activity|gis)$", # noqa: E501 {model}_{type} or {model}_view_{type}
7575
],
7676
"description": "View IDs should follow 'view_{model}_{type}' or '{model}_{type}' pattern",
7777
"examples": ["view_spp_program_form", "res_partner_tree", "ticket_view_form"],
@@ -109,7 +109,7 @@
109109
r"^group_[a-z0-9_]+_(viewer|officer|manager|admin|supervisor|approver|rejector|user|worker|requestor|validator|distributor|generator|registrar|reset|get|post|auditor|runner|editor)$",
110110
r"^group_[a-z0-9_]+_(read|write|create|delete|approve|reject)$",
111111
r"^group_[a-z0-9_]+_restrict_[a-z0-9_]+$", # Technical restriction groups
112-
r"^group_spp_[a-z0-9_]+_(agent|validator|applicator|administrator|external_api|local_validator|hq_validator)$", # Module-specific roles
112+
r"^group_spp_[a-z0-9_]+_(agent|validator|applicator|administrator|external_api|local_validator|hq_validator)$", # noqa: E501 Module-specific roles
113113
r"^category_[a-z0-9_]+$",
114114
],
115115
"description": "Group IDs should follow 'group_{domain}_{level}' or 'category_{domain}' pattern",

scripts/lint/openspp_lint.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@
4343
from .check_naming import NamingChecker
4444
from .check_performance import PerformanceChecker
4545
from .check_ui_patterns import UIPatternChecker
46-
from .check_xml_ids import XMLValidator, find_xml_files_in_module
46+
from .check_xml_ids import XMLValidator
4747
from .common import (
4848
LintConfig,
4949
OutputFormatter,
5050
Severity,
5151
Violation,
52-
get_summary_stats,
5352
print_summary,
5453
)
5554
except ImportError:
@@ -158,7 +157,7 @@ def _run_acl_check(self, root_dir: str, module: str = None):
158157
if module_path.exists():
159158
checker = ACLChecker(str(module_path.parent), self.config)
160159
# Filter to only check this module
161-
all_violations = checker.check_all_modules()
160+
checker.check_all_modules()
162161
checker.violations = [v for v in checker.violations if module in v.file_path]
163162
else:
164163
checker = ACLChecker(root_dir, self.config)

spp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ def _get_module_state(profile: str, module_name: str) -> str:
381381
"""Get the state of a module ('installed', 'to install', 'uninstalled', etc.)."""
382382
service = "openspp-dev" if profile == "dev" else "openspp"
383383
# Pass Python code via stdin (not -c which is for config file)
384-
code = f"m = env['ir.module.module'].search([('name', '=', '{module_name}')], limit=1); print('STATE:' + (m.state if m else 'NOT_FOUND'))"
384+
code = (
385+
f"m = env['ir.module.module'].search([('name', '=', '{module_name}')], limit=1); "
386+
f"print('STATE:' + (m.state if m else 'NOT_FOUND'))"
387+
)
385388
result = run(
386389
docker_compose(
387390
"exec",

spp_api_v2/models/api_extension.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ def get_extensions_for_resource(self, resource_type):
8585
_logger.warning("Unknown resource type: %s", resource_type)
8686
return self.env["spp.api.extension"]
8787

88-
return self.sudo().search( # nosemgrep: odoo-sudo-without-context - API extensions are configuration records; sudo() is used to read active extensions regardless of caller ACLs.
88+
return self.sudo().search( # nosemgrep: odoo-sudo-without-context
89+
# API extensions are configuration records; sudo() is used to read
90+
# active extensions regardless of caller ACLs.
8991
domain
9092
)
9193

spp_api_v2/services/auth_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import logging
99
from dataclasses import dataclass
1010

11+
import odoo
12+
1113
_logger = logging.getLogger(__name__)
1214

1315

spp_api_v2/services/extension_service.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ def get_extension_data(
4949
else:
5050
# Filter to requested extensions (by name, URL, or derived key)
5151
extensions_to_include = all_extensions.filtered(
52-
lambda e: e.name in extension_names
53-
or e.url in extension_names
54-
or self._get_extension_key(e) in extension_names
52+
lambda e: (
53+
e.name in extension_names
54+
or e.url in extension_names
55+
or self._get_extension_key(e) in extension_names
56+
)
5557
)
5658

5759
if not extensions_to_include:

0 commit comments

Comments
 (0)