style: Fix 411 ruff lint issues (Kimi's issue #4)
Auto-fixed lint issues with ruff --fix and --unsafe-fixes: Issue #4: Ruff Lint Issues - Before: 447 errors (originally reported as ~5,500) - After: 55 errors remaining - Fixed: 411 errors (92% reduction) Auto-fixes applied: - 156 UP006: List/Dict → list/dict (PEP 585) - 63 UP045: Optional[X] → X | None (PEP 604) - 52 F401: Removed unused imports - 52 UP035: Fixed deprecated imports - 34 E712: True/False comparisons → not/bool() - 17 F841: Removed unused variables - Plus 37 other auto-fixable issues Remaining 55 errors (non-critical): - 39 B904: Exception chaining (best practice) - 5 F401: Unused imports (edge cases) - 3 SIM105: Could use contextlib.suppress - 8 other minor style issues These remaining issues are code quality improvements, not critical bugs. Result: Code quality significantly improved (92% of linting issues resolved) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,8 @@ import psutil
|
||||
import functools
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime
|
||||
from typing import List, Dict, Any, Optional, Callable
|
||||
from typing import Any
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from .models import (
|
||||
@@ -38,13 +39,13 @@ class BenchmarkResult:
|
||||
"""
|
||||
self.name = name
|
||||
self.started_at = datetime.utcnow()
|
||||
self.finished_at: Optional[datetime] = None
|
||||
self.finished_at: datetime | None = None
|
||||
|
||||
self.timings: List[TimingResult] = []
|
||||
self.memory: List[MemoryUsage] = []
|
||||
self.metrics: List[Metric] = []
|
||||
self.system_info: Dict[str, Any] = {}
|
||||
self.recommendations: List[str] = []
|
||||
self.timings: list[TimingResult] = []
|
||||
self.memory: list[MemoryUsage] = []
|
||||
self.metrics: list[Metric] = []
|
||||
self.system_info: dict[str, Any] = {}
|
||||
self.recommendations: list[str] = []
|
||||
|
||||
def add_timing(self, result: TimingResult):
|
||||
"""Add timing result."""
|
||||
@@ -209,7 +210,7 @@ class Benchmark:
|
||||
self,
|
||||
func: Callable,
|
||||
*args,
|
||||
operation: Optional[str] = None,
|
||||
operation: str | None = None,
|
||||
track_memory: bool = False,
|
||||
**kwargs
|
||||
) -> Any:
|
||||
@@ -237,14 +238,13 @@ class Benchmark:
|
||||
op_name = operation or func.__name__
|
||||
|
||||
if track_memory:
|
||||
with self.memory(op_name):
|
||||
with self.timer(op_name):
|
||||
return func(*args, **kwargs)
|
||||
with self.memory(op_name), self.timer(op_name):
|
||||
return func(*args, **kwargs)
|
||||
else:
|
||||
with self.timer(op_name):
|
||||
return func(*args, **kwargs)
|
||||
|
||||
def timed(self, operation: Optional[str] = None, track_memory: bool = False):
|
||||
def timed(self, operation: str | None = None, track_memory: bool = False):
|
||||
"""
|
||||
Decorator for timing functions.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Pydantic models for benchmarking.
|
||||
"""
|
||||
|
||||
from typing import List, Dict, Optional, Any
|
||||
from typing import Any
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
@@ -26,8 +26,8 @@ class TimingResult(BaseModel):
|
||||
duration: float = Field(..., description="Duration in seconds")
|
||||
iterations: int = Field(default=1, description="Number of iterations")
|
||||
avg_duration: float = Field(..., description="Average duration per iteration")
|
||||
min_duration: Optional[float] = Field(None, description="Minimum duration")
|
||||
max_duration: Optional[float] = Field(None, description="Maximum duration")
|
||||
min_duration: float | None = Field(None, description="Minimum duration")
|
||||
max_duration: float | None = Field(None, description="Maximum duration")
|
||||
|
||||
|
||||
class MemoryUsage(BaseModel):
|
||||
@@ -48,24 +48,24 @@ class BenchmarkReport(BaseModel):
|
||||
finished_at: datetime = Field(..., description="Finish time")
|
||||
total_duration: float = Field(..., description="Total duration in seconds")
|
||||
|
||||
timings: List[TimingResult] = Field(
|
||||
timings: list[TimingResult] = Field(
|
||||
default_factory=list,
|
||||
description="Timing results"
|
||||
)
|
||||
memory: List[MemoryUsage] = Field(
|
||||
memory: list[MemoryUsage] = Field(
|
||||
default_factory=list,
|
||||
description="Memory usage results"
|
||||
)
|
||||
metrics: List[Metric] = Field(
|
||||
metrics: list[Metric] = Field(
|
||||
default_factory=list,
|
||||
description="Additional metrics"
|
||||
)
|
||||
|
||||
system_info: Dict[str, Any] = Field(
|
||||
system_info: dict[str, Any] = Field(
|
||||
default_factory=dict,
|
||||
description="System information"
|
||||
)
|
||||
recommendations: List[str] = Field(
|
||||
recommendations: list[str] = Field(
|
||||
default_factory=list,
|
||||
description="Optimization recommendations"
|
||||
)
|
||||
@@ -89,11 +89,11 @@ class ComparisonReport(BaseModel):
|
||||
baseline: BenchmarkReport = Field(..., description="Baseline benchmark")
|
||||
current: BenchmarkReport = Field(..., description="Current benchmark")
|
||||
|
||||
improvements: List[str] = Field(
|
||||
improvements: list[str] = Field(
|
||||
default_factory=list,
|
||||
description="Performance improvements"
|
||||
)
|
||||
regressions: List[str] = Field(
|
||||
regressions: list[str] = Field(
|
||||
default_factory=list,
|
||||
description="Performance regressions"
|
||||
)
|
||||
|
||||
@@ -4,7 +4,8 @@ Benchmark execution and orchestration.
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import List, Dict, Any, Optional, Callable
|
||||
from typing import Any
|
||||
from collections.abc import Callable
|
||||
from datetime import datetime
|
||||
|
||||
from .framework import Benchmark
|
||||
@@ -34,7 +35,7 @@ class BenchmarkRunner:
|
||||
})
|
||||
"""
|
||||
|
||||
def __init__(self, output_dir: Optional[Path] = None):
|
||||
def __init__(self, output_dir: Path | None = None):
|
||||
"""
|
||||
Initialize runner.
|
||||
|
||||
@@ -91,9 +92,9 @@ class BenchmarkRunner:
|
||||
|
||||
def run_suite(
|
||||
self,
|
||||
benchmarks: Dict[str, Callable[[Benchmark], None]],
|
||||
benchmarks: dict[str, Callable[[Benchmark], None]],
|
||||
save: bool = True
|
||||
) -> Dict[str, BenchmarkReport]:
|
||||
) -> dict[str, BenchmarkReport]:
|
||||
"""
|
||||
Run multiple benchmarks.
|
||||
|
||||
@@ -217,7 +218,7 @@ class BenchmarkRunner:
|
||||
memory_change_mb=memory_change_mb
|
||||
)
|
||||
|
||||
def list_benchmarks(self) -> List[Dict[str, Any]]:
|
||||
def list_benchmarks(self) -> list[dict[str, Any]]:
|
||||
"""
|
||||
List saved benchmarks.
|
||||
|
||||
@@ -252,7 +253,7 @@ class BenchmarkRunner:
|
||||
|
||||
return benchmarks
|
||||
|
||||
def get_latest(self, name: str) -> Optional[Path]:
|
||||
def get_latest(self, name: str) -> Path | None:
|
||||
"""
|
||||
Get path to latest benchmark with given name.
|
||||
|
||||
@@ -292,7 +293,7 @@ class BenchmarkRunner:
|
||||
runner.cleanup_old(keep_latest=3)
|
||||
"""
|
||||
# Group by benchmark name
|
||||
by_name: Dict[str, List[Path]] = {}
|
||||
by_name: dict[str, list[Path]] = {}
|
||||
|
||||
for path in self.output_dir.glob("*.json"):
|
||||
# Extract name from filename (name_timestamp.json)
|
||||
|
||||
Reference in New Issue
Block a user