Skip to content

Commit 7f56309

Browse files
art049claude
andcommitted
fix: resolve static analysis and mypy failures
- Add integration_name/integration_version params to Instrument base class - Move type-only imports to TYPE_CHECKING blocks (TC001/TC003) - Remove unused variables (F841) - Fix line length violations (E501) - Exclude TheAlgorithms submodule from ruff and mypy - Apply ruff format to all files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 422b1b7 commit 7f56309

15 files changed

Lines changed: 36 additions & 45 deletions

File tree

asv-codspeed/src/asv_codspeed/__main__.py

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

77
from asv_codspeed import __version__
88
from asv_codspeed.runner import run_benchmarks
9-
109
from codspeed.instruments import MeasurementMode
1110

1211

asv-codspeed/src/asv_codspeed/discovery.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import re
66
import sys
77
from dataclasses import dataclass, field
8-
from pathlib import Path
9-
from typing import Any, Callable
8+
from typing import TYPE_CHECKING
9+
10+
if TYPE_CHECKING:
11+
from pathlib import Path
12+
from typing import Any, Callable
1013

1114

1215
# ASV benchmark name patterns
@@ -84,9 +87,7 @@ def _import_module_from_path(module_name: str, file_path: Path):
8487
return module
8588

8689

87-
def _discover_from_module(
88-
module, module_name: str
89-
) -> list[ASVBenchmark]:
90+
def _discover_from_module(module, module_name: str) -> list[ASVBenchmark]:
9091
"""Discover benchmarks from a single module."""
9192
benchmarks = []
9293

@@ -207,8 +208,6 @@ def _create_benchmark(
207208
timeout = getattr(func, "timeout", getattr(source, "timeout", 60.0))
208209

209210
if params:
210-
# For now, create one benchmark per param combo
211-
benchmarks = []
212211
param_combos = _expand_params(params)
213212
if len(param_combos) == 1:
214213
return ASVBenchmark(

asv-codspeed/src/asv_codspeed/runner.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
import random
77
from pathlib import Path
88
from time import time
9-
from typing import TYPE_CHECKING, Any
9+
from typing import TYPE_CHECKING
1010

1111
from asv_codspeed.discovery import discover_benchmarks
12-
1312
from codspeed.config import BenchmarkMarkerOptions, CodSpeedConfig
14-
from codspeed.instruments import MeasurementMode, get_instrument_from_mode
13+
from codspeed.instruments import get_instrument_from_mode
1514
from codspeed.utils import get_environment_metadata, get_git_relative_path
1615

1716
if TYPE_CHECKING:
17+
from typing import Any
18+
1819
from asv_codspeed.discovery import ASVBenchmark
19-
from codspeed.instruments import Instrument
20+
from codspeed.instruments import Instrument, MeasurementMode
2021

2122

2223
def _get_uri(benchmark_name: str, benchmark_dir: Path) -> str:
@@ -140,8 +141,10 @@ def _report(
140141
instrument.print_benchmark_table()
141142

142143
total = passed + failed
143-
status = "passed" if failed == 0 else "with failures"
144-
console.print(f"\n[bold]===== {total} benchmarked ({passed} passed, {failed} failed) =====[/bold]")
144+
console.print(
145+
f"\n[bold]===== {total} benchmarked "
146+
f"({passed} passed, {failed} failed) =====[/bold]"
147+
)
145148

146149

147150
def _run_single_benchmark(

asv-codspeed/tests/test_cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
"""Tests for the asv-codspeed CLI."""
2+
23
from __future__ import annotations
34

45
import json
56
import subprocess
67
import sys
7-
from pathlib import Path
8-
9-
import pytest
108

119

1210
def test_cli_version():

asv-codspeed/tests/test_discovery.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
"""Tests for ASV benchmark discovery."""
2-
from __future__ import annotations
3-
4-
from pathlib import Path
52

6-
import pytest
3+
from __future__ import annotations
74

85
from asv_codspeed.discovery import discover_benchmarks
96

asv-codspeed/tests/test_runner.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""Tests for the ASV benchmark runner."""
2+
23
from __future__ import annotations
34

45
import json
5-
from pathlib import Path
6-
7-
import pytest
86

97
from asv_codspeed.runner import run_benchmarks
108

codspeed/src/codspeed/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import dataclasses
43
from dataclasses import dataclass, field
54
from typing import TYPE_CHECKING, Generic, TypeVar
65

codspeed/src/codspeed/instruments/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ class Instrument(metaclass=ABCMeta):
1919
instrument: ClassVar[str]
2020

2121
@abstractmethod
22-
def __init__(self, config: CodSpeedConfig): ...
22+
def __init__(
23+
self,
24+
config: CodSpeedConfig,
25+
integration_name: str = "pytest-codspeed",
26+
integration_version: str = "0.0.0",
27+
): ...
2328

2429
@abstractmethod
2530
def get_instrument_config_str_and_warns(self) -> tuple[str, list[str]]: ...

codspeed/src/codspeed/instruments/valgrind.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
if TYPE_CHECKING:
1212
from typing import Any, Callable
1313

14-
from codspeed.config import CodSpeedConfig, PedanticOptions
14+
from codspeed.config import BenchmarkMarkerOptions, CodSpeedConfig, PedanticOptions
1515
from codspeed.instruments import P, T
16-
from codspeed.config import BenchmarkMarkerOptions
1716

1817

1918
class ValgrindInstrument(Instrument):
@@ -29,9 +28,7 @@ def __init__(
2928
self.benchmark_count = 0
3029
try:
3130
self.instrument_hooks = InstrumentHooks()
32-
self.instrument_hooks.set_integration(
33-
integration_name, integration_version
34-
)
31+
self.instrument_hooks.set_integration(integration_name, integration_version)
3532
except RuntimeError as e:
3633
if os.environ.get("CODSPEED_ENV") is not None:
3734
raise Exception(

codspeed/src/codspeed/instruments/walltime.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ def __init__(
163163
) -> None:
164164
try:
165165
self.instrument_hooks = InstrumentHooks()
166-
self.instrument_hooks.set_integration(
167-
integration_name, integration_version
168-
)
166+
self.instrument_hooks.set_integration(integration_name, integration_version)
169167
except RuntimeError as e:
170168
if os.environ.get("CODSPEED_ENV") is not None:
171169
warnings.warn(

0 commit comments

Comments
 (0)