Skip to content

Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)

Python

Added ruff check to workflow and fixed ruff check errors

Alishahryar1ad44594197ab
diff --git a/api/app.py b/api/app.py
index 16fa3b87..c7bd24a8 100644
--- a/api/app.py
+++ b/api/app.py
@@ -2,27 +2,25 @@
import asyncio
import os
-
-# Opt-in to future behavior for python-telegram-bot
-os.environ["PTB_TIMEDELTA"] = "1"
-
from contextlib import asynccontextmanager
+
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
+from loguru import logger
from config.settings import get_settings
from config.logging_config import configure_logging
+from .routes import router
+from .dependencies import cleanup_provider
+from providers.exceptions import ProviderError
+
+# Opt-in to future behavior for python-telegram-bot
+os.environ["PTB_TIMEDELTA"] = "1"
# Configure logging first (before any module logs)
_settings = get_settings()
configure_logging(_settings.log_file)
-from loguru import logger
-
-from .routes import router
-from .dependencies import cleanup_provider
-from providers.exceptions import ProviderError
-
_SHUTDOWN_TIMEOUT_S = 5.0
diff --git a/messaging/telegram.py b/messaging/telegram.py
index 24f3ac4a..04b40782 100644
--- a/messaging/telegram.py
+++ b/messaging/telegram.py
@@ -22,7 +22,7 @@ from .telegram_markdown import escape_md_v2
# Optional import - python-telegram-bot may not be installed
try:
- from telegram import Update, Bot
+ from telegram import Update
from telegram.ext import (
Application,
CommandHandler,
@@ -161,14 +161,12 @@ class TelegramPlatform(MessagingPlatform):
) -> Any:
"""Helper to execute a function with exponential backoff on network errors."""
max_retries = 3
- last_error = None
for attempt in range(max_retries):
try:
return await func(*args, **kwargs)
except (NetworkError, asyncio.TimeoutError) as e:
if "Message is not modified" in str(e):
return None
- last_error = e
if attempt < max_retries - 1:
wait_time = 2**attempt # 1s, 2s, 4s
logger.warning(
diff --git a/tests/test_handler.py b/tests/test_handler.py
index d1208c30..6b387a8f 100644
--- a/tests/test_handler.py
+++ b/tests/test_handler.py
@@ -149,9 +149,7 @@ async def test_handle_message_queued(handler, mock_platform, incoming_message_fa
with (
patch.object(handler.tree_queue, "create_tree", AsyncMock()) as mock_create,
- patch.object(
- handler.tree_queue, "enqueue", AsyncMock(return_value=True)
- ) as mock_enqueue,
+ patch.object(handler.tree_queue, "enqueue", AsyncMock(return_value=True)),
patch.object(handler.tree_queue, "get_queue_size", MagicMock(return_value=3)),
):
mock_tree = MagicMock()
diff --git a/tests/test_lmstudio.py b/tests/test_lmstudio.py
index 60d36057..5a1b15ef 100644
--- a/tests/test_lmstudio.py
+++ b/tests/test_lmstudio.py
@@ -143,7 +143,7 @@ def test_init_with_empty_api_key():
rate_window=60,
nim_settings=NimSettings(),
)
- with patch("providers.lmstudio.client.AsyncOpenAI") as mock_openai:
+ with patch("providers.lmstudio.client.AsyncOpenAI"):
provider = LMStudioProvider(config)
assert provider._api_key == "lm-studio"
@@ -639,6 +639,6 @@ def test_init_base_url_strips_trailing_slash():
rate_window=60,
nim_settings=NimSettings(),
)
- with patch("providers.lmstudio.client.AsyncOpenAI") as mock_openai:
+ with patch("providers.lmstudio.client.AsyncOpenAI"):
provider = LMStudioProvider(config)
assert provider._base_url == "http://localhost:1234/v1"
diff --git a/tests/test_logging_config.py b/tests/test_logging_config.py
index 18dcc119..117898b6 100644
--- a/tests/test_logging_config.py
+++ b/tests/test_logging_config.py
@@ -23,7 +23,7 @@ def test_configure_logging_writes_json_to_file(tmp_path):
loguru_logger.complete()
content = Path(log_file).read_text(encoding="utf-8")
- lines = [l for l in content.strip().split("\n") if l]
+ lines = [line for line in content.strip().split("\n") if line]
assert len(lines) >= 1
# Each line should be valid JSON
diff --git a/tests/test_messaging.py b/tests/test_messaging.py
index f3c119c9..13782321 100644
--- a/tests/test_messaging.py
+++ b/tests/test_messaging.py
@@ -223,7 +223,7 @@ class TestTreeQueueManager:
text="test", chat_id="1", user_id="1", message_id="1", platform="test"
)
- tree = await mgr.create_tree("1", incoming, "status_1")
+ await mgr.create_tree("1", incoming, "status_1")
was_queued = await mgr.enqueue("1", processor)
# First message should process immediately, not queue
diff --git a/tests/test_parsers.py b/tests/test_parsers.py
index 7473d2c7..89e3c537 100644
--- a/tests/test_parsers.py
+++ b/tests/test_parsers.py
@@ -333,7 +333,7 @@ def test_orphan_close_with_valid_think_pair():
chunks = list(parser.feed("a</think>b<think>thinking</think>c"))
types = [c.type for c in chunks]
- contents = [c.content for c in chunks]
+ # contents = [c.content for c in chunks] # Unused
assert ContentType.TEXT in types
assert ContentType.THINKING in types
@@ -418,7 +418,7 @@ def test_think_tag_parser_empty_think_tags():
parser = ThinkTagParser()
chunks = list(parser.feed("<think></think>remaining"))
# Empty think yields nothing for thinking, just the remaining text
- types = [c.type for c in chunks]
+ # types = [c.type for c in chunks] # Unused
text = "".join(c.content for c in chunks if c.type == ContentType.TEXT)
assert text == "remaining"
diff --git a/tests/test_sse_builder.py b/tests/test_sse_builder.py
index b4bbfe9d..1ed58f92 100644
--- a/tests/test_sse_builder.py
+++ b/tests/test_sse_builder.py
@@ -209,7 +209,7 @@ class TestSSEBuilderHighLevelHelpers:
assert builder.blocks.text_started is True
assert builder.blocks.text_index == 0
- stop_sse = builder.stop_text_block()
+ builder.stop_text_block()
assert builder.blocks.text_started is False
def test_emit_text_delta_accumulates(self):
diff --git a/tests/test_tree_concurrency.py b/tests/test_tree_concurrency.py
index bc63ab9a..f1a14f0c 100644
--- a/tests/test_tree_concurrency.py
+++ b/tests/test_tree_concurrency.py
@@ -342,7 +342,7 @@ class TestTreeQueueManagerConcurrency:
async def test_enqueue_and_process(self):
"""Enqueue should process immediately if tree is free."""
mgr = TreeQueueManager()
- tree = await mgr.create_tree("root", _make_incoming(msg_id="root"), "s_root")
+ await mgr.create_tree("root", _make_incoming(msg_id="root"), "s_root")
processed = []
@@ -361,7 +361,7 @@ class TestTreeQueueManagerConcurrency:
async def test_enqueue_queues_when_busy(self):
"""Enqueue should queue when tree is already processing."""
mgr = TreeQueueManager()
- tree = await mgr.create_tree("root", _make_incoming(msg_id="root"), "s_root")
+ await mgr.create_tree("root", _make_incoming(msg_id="root"), "s_root")
_, _ = await mgr.add_to_tree("root", "c1", _make_incoming(msg_id="c1"), "s1")
processing_started = asyncio.Event()
@@ -583,7 +583,7 @@ class TestTreeQueueManagerConcurrency:
queue_update_callback=on_queue_update,
node_started_callback=on_node_started,
)
- tree = await mgr.create_tree("root", _make_incoming(msg_id="root"), "s_root")
+ await mgr.create_tree("root", _make_incoming(msg_id="root"), "s_root")
_, _ = await mgr.add_to_tree("root", "c1", _make_incoming(msg_id="c1"), "s1")
blocker = asyncio.Event()