Skip to content

Commit b49b0be

Browse files
randclaude
andcommitted
fix: resolve all ty and ruff static analysis errors
Fix 4 type checker diagnostics and 19 linter errors: - Remove duplicate DifficultyEstimate import (F811) - Simplify conditional returns (SIM103) - Remove unused variables (F841) - Move imports to top of file (E402) - Chain exceptions properly (B904) - Add unreachable guards for implicit None returns (ty) - Guard .get() on possibly-None dict (ty) - Suppress proxy pattern type mismatch (ty) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 99a72ef commit b49b0be

9 files changed

Lines changed: 30 additions & 51 deletions

File tree

src/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@
204204
# Learned routing (SPEC-06.20-06.26)
205205
from .learned_routing import (
206206
CascadingRouter,
207-
DifficultyEstimate,
208207
DifficultyEstimator,
209208
LearnedRouter,
210209
ModelProfile,

src/circuit_breaker.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,7 @@ def allow_request(self) -> bool:
155155
Returns:
156156
True if request is allowed
157157
"""
158-
if self._state == CircuitState.CLOSED:
159-
return True
160-
elif self._state == CircuitState.HALF_OPEN:
161-
return True # Allow probe request
162-
else: # OPEN
163-
return False
158+
return self._state in (CircuitState.CLOSED, CircuitState.HALF_OPEN)
164159

165160
def record_failure(
166161
self,

src/context_enrichment.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ def gather_types(self, content: str) -> dict[str, Any]:
234234
class_pattern = r"class\s+(\w+)(?:\([^)]*\))?:"
235235
for match in re.finditer(class_pattern, content):
236236
class_name = match.group(1)
237-
# Find class body (simplified)
238-
start = match.end()
239237
types[class_name] = {"kind": "class", "position": match.start()}
240238

241239
# Match type annotations
@@ -462,9 +460,6 @@ def enrich(
462460
# Classify intent
463461
intent = self.classifier.classify(query)
464462

465-
# Get strategy for intent
466-
strategy = EnrichmentStrategy.for_intent(intent)
467-
468463
# Gather enrichment data
469464
enriched = dict(context)
470465
additions: list[str] = []

src/memory_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def _get_connection(self) -> sqlite3.Connection:
397397
and threading.get_ident() == self._owner_thread_id
398398
):
399399
self._persistent_conn.row_factory = sqlite3.Row
400-
return _NoCloseConnection(self._persistent_conn)
400+
return _NoCloseConnection(self._persistent_conn) # type: ignore[return-value]
401401

402402
# Use thread-local connections for non-owner threads to avoid sqlite
403403
# thread-affinity errors when tests exercise concurrent session access.

src/orchestrator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ async def execute_op_bounded(op: DeferredOperation) -> tuple[str, Any, dict[str,
658658
"error": str(e),
659659
}
660660
await asyncio.sleep(retry_backoff_s * attempt)
661+
raise RuntimeError(f"Unreachable: max_attempts={max_attempts}")
661662

662663
# Execute all operations in parallel with bounded concurrency
663664
results = await asyncio.gather(*[execute_op_bounded(op) for op in all_ops])

src/orchestrator/core.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,33 @@
2020
from collections.abc import AsyncIterator
2121
from dataclasses import dataclass, field
2222
from enum import Enum
23-
from typing import TYPE_CHECKING, Any
23+
from typing import Any
2424

2525
from ..api_client import ClaudeClient, Provider, init_client
26+
from ..complexity_classifier import should_activate_rlm
27+
from ..config import RLMConfig, default_config
28+
from ..context_manager import externalize_context
29+
from ..cost_tracker import CostComponent, get_cost_tracker
30+
from ..epistemic import (
31+
ClaimExtractor,
32+
EvidenceAuditor,
33+
HallucinationReport,
34+
VerificationConfig,
35+
)
2636
from ..memory_store import MemoryStore
37+
from ..prompts import build_rlm_system_prompt
38+
from ..recursive_handler import RecursiveREPL
39+
from ..repl_environment import RLMEnvironment
40+
from ..response_parser import ResponseAction, ResponseParser
41+
from ..smart_router import SmartRouter
2742
from ..state_persistence import StatePersistence
43+
from ..trajectory import (
44+
StreamingTrajectory,
45+
TrajectoryEvent,
46+
TrajectoryEventType,
47+
TrajectoryRenderer,
48+
)
49+
from ..types import DeferredOperation, SessionContext
2850

2951
# ============================================================================
3052
# Error Recovery (SPEC-12.10)
@@ -65,36 +87,6 @@ class Checkpoint:
6587
repl_state: dict[str, Any]
6688

6789

68-
# ============================================================================
69-
# Core Imports
70-
# ============================================================================
71-
72-
from ..complexity_classifier import should_activate_rlm
73-
from ..config import RLMConfig, default_config
74-
from ..context_manager import externalize_context
75-
from ..cost_tracker import CostComponent, get_cost_tracker
76-
from ..epistemic import (
77-
ClaimExtractor,
78-
EvidenceAuditor,
79-
HallucinationReport,
80-
VerificationConfig,
81-
)
82-
from ..prompts import build_rlm_system_prompt
83-
from ..recursive_handler import RecursiveREPL
84-
from ..repl_environment import RLMEnvironment
85-
from ..response_parser import ResponseAction, ResponseParser
86-
from ..smart_router import SmartRouter
87-
from ..trajectory import (
88-
StreamingTrajectory,
89-
TrajectoryEvent,
90-
TrajectoryEventType,
91-
TrajectoryRenderer,
92-
)
93-
from ..types import DeferredOperation, SessionContext
94-
95-
if TYPE_CHECKING:
96-
pass
97-
9890

9991
@dataclass
10092
class OrchestrationState:
@@ -833,6 +825,7 @@ async def execute_op_bounded(op: DeferredOperation) -> tuple[str, Any, dict[str,
833825
"error": str(e),
834826
}
835827
await asyncio.sleep(retry_backoff_s * attempt)
828+
raise RuntimeError(f"Unreachable: max_attempts={max_attempts}")
836829

837830
# Execute all operations in parallel with bounded concurrency
838831
results = await asyncio.gather(*[execute_op_bounded(op) for op in all_ops])

src/orchestrator/steering.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,7 @@ def should_present_steering(
291291
if cost_usd is not None and cost_usd > 0.5:
292292
return True
293293

294-
if turn in {10, 20, 30, 40}:
295-
return True
296-
297-
return False
294+
return turn in {10, 20, 30, 40}
298295

299296
def should_steer(
300297
self,

src/proactive_computation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def calc(self, expression: str) -> Any:
244244
tree = ast.parse(expression, mode="eval")
245245
return self._eval_node(tree.body)
246246
except (SyntaxError, TypeError) as e:
247-
raise ValueError(f"Invalid expression: {e}")
247+
raise ValueError(f"Invalid expression: {e}") from e
248248

249249
def _eval_node(self, node: ast.AST) -> Any:
250250
"""Recursively evaluate an AST node."""
@@ -530,7 +530,6 @@ def _generate_code(
530530
# Extract numbers and operations from query
531531
numbers = re.findall(r"\d+(?:\.\d+)?", query)
532532
if len(numbers) >= 2:
533-
expr = query
534533
# Try to find the expression
535534
match = re.search(r"(\d+(?:\.\d+)?)\s*([+\-*/^])\s*(\d+(?:\.\d+)?)", query)
536535
if match:

src/repl_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ def _validate_submit_outputs(self, outputs: Any) -> list[dict[str, Any]]:
734734
}
735735
]
736736

737-
output_fields = self._signature_registration.get("output_fields", [])
737+
output_fields = (self._signature_registration or {}).get("output_fields", [])
738738
for field_spec in output_fields:
739739
field_name = field_spec.get("name", "")
740740
field_type = field_spec.get("field_type", {"type": "custom", "value": "unknown"})

0 commit comments

Comments
 (0)