From 5ee96721f7c49673a80d8f5c75ba6df85f1068cf Mon Sep 17 00:00:00 2001 From: Jiajun Xie Date: Mon, 6 Apr 2026 19:35:06 +0800 Subject: [PATCH] ci: add ruff lint check for unused imports and variables Add CI step to detect unused imports (F401) and unused variables (F841) with ruff. Clean up existing violations: - Remove unused Consolidator import in agent/__init__.py - Remove unused re import in agent/loop.py - Remove unused Path import in channels/feishu.py - Remove unused ContentRepositoryConfigError import in channels/matrix.py - Remove unused field and CommandHandler imports in channels/telegram.py - Remove unused exception variable in channels/weixin.py --- .github/workflows/ci.yml | 3 +++ nanobot/agent/__init__.py | 2 +- nanobot/agent/loop.py | 1 - nanobot/channels/feishu.py | 1 - nanobot/channels/matrix.py | 1 - nanobot/channels/telegram.py | 4 ++-- nanobot/channels/weixin.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e00362d02..fac9be66c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,5 +30,8 @@ jobs: - name: Install all dependencies run: uv sync --all-extras + - name: Lint with ruff + run: uv run ruff check nanobot --select F401,F841 + - name: Run tests run: uv run pytest tests/ diff --git a/nanobot/agent/__init__.py b/nanobot/agent/__init__.py index a8805a3ad..9eef5a0c6 100644 --- a/nanobot/agent/__init__.py +++ b/nanobot/agent/__init__.py @@ -3,7 +3,7 @@ from nanobot.agent.context import ContextBuilder from nanobot.agent.hook import AgentHook, AgentHookContext, CompositeHook from nanobot.agent.loop import AgentLoop -from nanobot.agent.memory import Consolidator, Dream, MemoryStore +from nanobot.agent.memory import Dream, MemoryStore from nanobot.agent.skills import SkillsLoader from nanobot.agent.subagent import SubagentManager diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index 93dcaabec..9e5ca0bc9 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -4,7 +4,6 @@ from __future__ import annotations import asyncio import json -import re import os import time from contextlib import AsyncExitStack, nullcontext diff --git a/nanobot/channels/feishu.py b/nanobot/channels/feishu.py index 4798b818b..c6124d0c9 100644 --- a/nanobot/channels/feishu.py +++ b/nanobot/channels/feishu.py @@ -9,7 +9,6 @@ import time import uuid from collections import OrderedDict from dataclasses import dataclass -from pathlib import Path from typing import Any, Literal from loguru import logger diff --git a/nanobot/channels/matrix.py b/nanobot/channels/matrix.py index a1435fcf3..85a167a3a 100644 --- a/nanobot/channels/matrix.py +++ b/nanobot/channels/matrix.py @@ -18,7 +18,6 @@ try: from nio import ( AsyncClient, AsyncClientConfig, - ContentRepositoryConfigError, DownloadError, InviteEvent, JoinError, diff --git a/nanobot/channels/telegram.py b/nanobot/channels/telegram.py index 07ea7cb05..aeb36d8e4 100644 --- a/nanobot/channels/telegram.py +++ b/nanobot/channels/telegram.py @@ -6,14 +6,14 @@ import asyncio import re import time import unicodedata -from dataclasses import dataclass, field +from dataclasses import dataclass from typing import Any, Literal from loguru import logger from pydantic import Field from telegram import BotCommand, ReactionTypeEmoji, ReplyParameters, Update from telegram.error import BadRequest, NetworkError, TimedOut -from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters +from telegram.ext import Application, ContextTypes, MessageHandler, filters from telegram.request import HTTPXRequest from nanobot.bus.events import OutboundMessage diff --git a/nanobot/channels/weixin.py b/nanobot/channels/weixin.py index 2266bc9f0..3f87e2203 100644 --- a/nanobot/channels/weixin.py +++ b/nanobot/channels/weixin.py @@ -484,7 +484,7 @@ class WeixinChannel(BaseChannel): except httpx.TimeoutException: # Normal for long-poll, just retry continue - except Exception as e: + except Exception: if not self._running: break consecutive_failures += 1