Skip to content

Commit d7fc4c6

Browse files
committed
Fix ruff lint errors and configure ignore rules
- Convert .format() to f-strings (UP032, 38 auto-fixed) - Rename ambiguous variable 'l' to 'line' (E741) - Rename unused loop variable to _page (B007) - Shorten long docstring (E501) - Add ignore rules for style-only lint rules (UP042, TCH001, SIM108, B905, B017) - Add per-file E501 ignore for template strings
1 parent 4510ad3 commit d7fc4c6

9 files changed

Lines changed: 25 additions & 34 deletions

File tree

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ select = [
8383
"TCH", # flake8-type-checking
8484
"RUF", # ruff-specific
8585
]
86+
ignore = [
87+
"UP042", # str+Enum to StrEnum — keep for Python 3.10 compat
88+
"TCH001", # move imports to TYPE_CHECKING — impacts runtime imports
89+
"SIM108", # ternary operator — sometimes explicit if/else is clearer
90+
"B905", # zip strict — not needed for trusted same-length sequences
91+
"B017", # blind Exception — used for duckdb which raises generic errors
92+
]
93+
94+
[tool.ruff.lint.per-file-ignores]
95+
"src/evalkit/generators/templates.py" = ["E501"] # template strings have long lines
8696

8797
[tool.mypy]
8898
python_version = "3.11"

src/evalkit/regression/comparator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def _structural_compare(self, output_a: str, output_b: str) -> ComparisonResult:
192192
line_sim = 1.0 - abs(len_a - len_b) / max_lines
193193

194194
# Average line length similarity
195-
avg_len_a = sum(len(l) for l in lines_a) / max(len_a, 1)
196-
avg_len_b = sum(len(l) for l in lines_b) / max(len_b, 1)
195+
avg_len_a = sum(len(line) for line in lines_a) / max(len_a, 1)
196+
avg_len_b = sum(len(line) for line in lines_b) / max(len_b, 1)
197197
max_avg = max(avg_len_a, avg_len_b, 1)
198198
len_sim = 1.0 - abs(avg_len_a - avg_len_b) / max_avg
199199

src/evalkit/regression/reporter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from __future__ import annotations
88

9-
import json
109
from typing import Any
1110

1211
import structlog

tests/test_api_contracts.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
import json
1111
import os
1212
import tempfile
13-
from datetime import datetime, timezone
13+
from datetime import datetime
1414
from pathlib import Path
15-
from typing import Any
16-
from unittest.mock import MagicMock, patch
15+
from unittest.mock import patch
1716

1817
import pytest
1918
from pydantic import ValidationError
@@ -41,7 +40,7 @@
4140
from evalkit.generators.templates import GenerationStrategy, render_template
4241
from evalkit.judges.base import BaseJudge
4342
from evalkit.judges.ensemble import EnsembleJudge
44-
from evalkit.judges.llm_judge import LLMJudge, _build_evaluation_prompt, _parse_judge_response
43+
from evalkit.judges.llm_judge import LLMJudge
4544
from evalkit.judges.rubrics import (
4645
FACTUAL_ACCURACY_RUBRIC,
4746
HELPFULNESS_RUBRIC,
@@ -53,7 +52,6 @@
5352
from evalkit.regression.reporter import RegressionReporter
5453
from evalkit.regression.tracker import RegressionTracker
5554

56-
5755
# ===========================================================================
5856
# Section 1: Core Models -- Parameter validation and type contracts
5957
# ===========================================================================

tests/test_generators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
from evalkit.generators.synthetic import SyntheticGenerator
1111
from evalkit.generators.templates import (
12-
GenerationStrategy,
1312
STRATEGY_TEMPLATES,
13+
GenerationStrategy,
1414
render_template,
1515
)
1616

tests/test_judges.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from evalkit.core.models import (
1111
JudgeScore,
1212
Rubric,
13-
RubricCriteria,
1413
ScoreScale,
1514
VotingStrategy,
1615
)
@@ -29,7 +28,6 @@
2928
build_rubric,
3029
)
3130

32-
3331
# ---------------------------------------------------------------------------
3432
# Concrete stub for testing BaseJudge
3533
# ---------------------------------------------------------------------------

tests/test_non_functional.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515
import os
1616
import tempfile
1717
import time
18-
import threading
19-
from datetime import datetime, timezone
2018
from pathlib import Path
21-
from typing import Any
22-
from unittest.mock import MagicMock, patch
19+
from unittest.mock import patch
2320

2421
import pytest
2522
from pydantic import ValidationError
2623

2724
from evalkit.core.config import (
2825
EnsembleConfig,
2926
EvalConfig,
30-
JudgeConfig,
3127
LLMProviderConfig,
3228
StorageConfig,
3329
)
@@ -38,21 +34,17 @@
3834
RegressionReport,
3935
Rubric,
4036
RubricCriteria,
41-
ScoreScale,
4237
VotingStrategy,
4338
)
4439
from evalkit.core.storage import DuckDBStorage
4540
from evalkit.generators.synthetic import SyntheticGenerator
46-
from evalkit.generators.templates import GenerationStrategy, render_template
4741
from evalkit.judges.base import BaseJudge
4842
from evalkit.judges.ensemble import EnsembleJudge
4943
from evalkit.judges.llm_judge import LLMJudge, _parse_judge_response
50-
from evalkit.judges.rubrics import build_rubric
5144
from evalkit.regression.comparator import ComparisonMethod, OutputComparator
5245
from evalkit.regression.reporter import RegressionReporter
5346
from evalkit.regression.tracker import RegressionTracker
5447

55-
5648
# ---------------------------------------------------------------------------
5749
# Helpers
5850
# ---------------------------------------------------------------------------
@@ -133,11 +125,13 @@ def test_unsupported_provider_raises(self) -> None:
133125
judge = LLMJudge(judge_id="j1", rubric=rubric, llm_config=config)
134126

135127
# Mock the api_key property to bypass env var check, then call _call_llm directly
136-
with patch.object(
137-
LLMProviderConfig, "api_key", new_callable=lambda: property(lambda self: "dummy")
128+
with (
129+
patch.object(
130+
LLMProviderConfig, "api_key", new_callable=lambda: property(lambda self: "dummy")
131+
),
132+
pytest.raises(ValueError, match="Unsupported provider"),
138133
):
139-
with pytest.raises(ValueError, match="Unsupported provider"):
140-
judge._call_llm("test prompt")
134+
judge._call_llm("test prompt")
141135

142136
def test_bad_json_from_llm_raises(self) -> None:
143137
"""If LLM returns invalid JSON, evaluate should raise ValueError."""
@@ -269,7 +263,7 @@ def test_from_yaml_invalid_field_type(self) -> None:
269263
Path(path).unlink()
270264

271265
def test_from_yaml_with_extra_fields(self) -> None:
272-
"""Pydantic should accept extra fields without error (by default model is strict=False for extras)."""
266+
"""Pydantic accepts extra fields without error (strict=False for extras)."""
273267
import yaml
274268

275269
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f:

tests/test_scaling.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,18 @@
1010
from __future__ import annotations
1111

1212
import time
13-
from typing import Any
1413

1514
import pytest
1615

1716
from evalkit.core.models import (
1817
EvalResult,
1918
JudgeScore,
20-
Rubric,
21-
RubricCriteria,
22-
ScoreScale,
23-
VotingStrategy,
2419
)
2520
from evalkit.core.storage import DuckDBStorage
2621
from evalkit.regression.comparator import ComparisonMethod, OutputComparator
2722
from evalkit.regression.reporter import RegressionReporter
2823
from evalkit.regression.tracker import RegressionTracker
2924

30-
3125
# ---------------------------------------------------------------------------
3226
# Helpers
3327
# ---------------------------------------------------------------------------
@@ -256,7 +250,7 @@ def test_get_results_pagination_like_pattern(self) -> None:
256250

257251
# Query in pages of 50
258252
pages_total = 0
259-
for page in range(10):
253+
for _page in range(10):
260254
queried = s.get_results(limit=50)
261255
pages_total += len(queried)
262256
assert len(queried) == 50 # limit works

tests/test_storage.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
import pytest
6-
75
from evalkit.core.models import EvalResult
86
from evalkit.core.storage import DuckDBStorage
97

0 commit comments

Comments
 (0)