From 15bd6f42bb01e3803d1bcb2e2f4354d3d8c0270b Mon Sep 17 00:00:00 2001 From: KoalaTrapLord <265133236+KoalaTrapLord@users.noreply.github.com> Date: Thu, 26 Mar 2026 15:30:27 -0400 Subject: [PATCH] fix: resolve all ruff linting errors across coach module --- coach/coach_service.py | 50 +++++++++++++++++----------------- coach/embeddings.py | 2 -- coach/models.py | 1 - coach/prompt_template.py | 1 - coach/prompts/deck_gen_user.py | 6 ++-- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/coach/coach_service.py b/coach/coach_service.py index f6ac10e..c4f2f40 100644 --- a/coach/coach_service.py +++ b/coach/coach_service.py @@ -279,32 +279,32 @@ class CoachService: import anthropic anthropic_key = ANTHROPIC_API_KEY if not anthropic_key: - raise ConnectionError("Anthropic API key not configured. Set ANTHROPIC_API_KEY env var.") + raise ConnectionError("Anthropic API key not configured. Set ANTHROPIC_API_KEY env var.") aclient = anthropic.AsyncAnthropic(api_key=anthropic_key) - resp = await aclient.messages.create( - model=ANTHROPIC_MODEL, - system=system_prompt, - messages=[{"role": "user", "content": user_prompt}], - max_tokens=8192, - temperature=0.7, - ) - content = resp.content[0].text if resp.content else "" - usage = resp.usage + resp = await aclient.messages.create( + model=ANTHROPIC_MODEL, + system=system_prompt, + messages=[{"role": "user", "content": user_prompt}], + max_tokens=8192, + temperature=0.7, + ) + content = resp.content[0].text if resp.content else "" + usage = resp.usage - # Build an LLMResponse-compatible object - from types import SimpleNamespace - llm_response = SimpleNamespace( - content=content, - model=resp.model, - prompt_tokens=usage.input_tokens if usage else 0, - completion_tokens=usage.output_tokens if usage else 0, - parsed_json=None, - ) - try: - cleaned = re.sub(r'^```(?:json)?\s*', '', content.strip()) - cleaned = re.sub(r'\s*```$', '', cleaned.strip()) - llm_response.parsed_json = json.loads(cleaned) - except (json.JSONDecodeError, ValueError): + # Build an LLMResponse-compatible object + from types import SimpleNamespace + llm_response = SimpleNamespace( + content=content, + model=resp.model, + prompt_tokens=usage.input_tokens if usage else 0, + completion_tokens=usage.output_tokens if usage else 0, + parsed_json=None, + ) + try: + cleaned = re.sub(r'^```(?:json)?\s*', '', content.strip()) + cleaned = re.sub(r'\s*```$', '', cleaned.strip()) + llm_response.parsed_json = json.loads(cleaned) + except (json.JSONDecodeError, ValueError): # Try to find JSON object in the text match = re.search(r'\{[\s\S]*\}', content) if match: @@ -313,7 +313,7 @@ class CoachService: except json.JSONDecodeError: pass else: - llm_response = await self.llm.chat(system_prompt, user_prompt) + llm_response = await self.llm.chat(system_prompt, user_prompt) # 6. Parse response into CoachSession session_id = f"sess-{datetime.now(timezone.utc).strftime('%Y%m%d-%H%M%S')}-{uuid.uuid4().hex[:6]}" diff --git a/coach/embeddings.py b/coach/embeddings.py index a9f8092..e218054 100644 --- a/coach/embeddings.py +++ b/coach/embeddings.py @@ -21,7 +21,6 @@ import json import logging import re import os -import time from pathlib import Path from typing import List, Optional, Tuple from urllib.request import urlopen, Request @@ -331,7 +330,6 @@ class MTGEmbeddingIndex: d = np.load(str(CUSTOM_CACHE_PATH), allow_pickle=True) for n in d["names"]: existing_names.add(n.lower()) - existing = dict(d) except Exception: pass diff --git a/coach/models.py b/coach/models.py index 812c9fb..4fa52b6 100644 --- a/coach/models.py +++ b/coach/models.py @@ -5,7 +5,6 @@ Pydantic v2 models for deck reports, coach requests/responses, and coaching session persistence. """ -from datetime import datetime from typing import List, Optional, Dict from pydantic import BaseModel, Field diff --git a/coach/prompt_template.py b/coach/prompt_template.py index c9f060d..da734c8 100644 --- a/coach/prompt_template.py +++ b/coach/prompt_template.py @@ -6,7 +6,6 @@ Injects deck report data, underperformer analysis, and candidate replacement cards into a structured template. """ -import json from typing import List, Dict, Optional from .models import DeckReport, CoachGoals, CardPerformance diff --git a/coach/prompts/deck_gen_user.py b/coach/prompts/deck_gen_user.py index 7f92768..9fdea5a 100644 --- a/coach/prompts/deck_gen_user.py +++ b/coach/prompts/deck_gen_user.py @@ -5,7 +5,7 @@ Constructs the user message for Claude Opus deck generation from a DeckGenV3Request. """ -from typing import List, Optional +from typing import List def build_user_prompt( @@ -36,8 +36,8 @@ def build_user_prompt( ci_str = ", ".join(color_identity) if color_identity else "Unknown" lines = [ - f"Build a complete 100-card Commander deck.", - f"", + "Build a complete 100-card Commander deck.", + "", f"COMMANDER: {commander}", ]