From 0c486404129b5a7679904cc5ba4b2bd3fe65d17f Mon Sep 17 00:00:00 2001 From: Francwa Date: Sun, 7 Dec 2025 05:59:53 +0100 Subject: [PATCH] Fixed all ruff issues --- agent/llm/deepseek.py | 2 +- agent/llm/ollama.py | 2 +- agent/prompts.py | 17 +++++++---------- app.py | 4 ++-- infrastructure/api/qbittorrent/client.py | 2 +- infrastructure/api/tmdb/client.py | 1 - infrastructure/filesystem/file_manager.py | 8 ++++++-- pyproject.toml | 6 +++--- tests/test_domain_edge_cases.py | 2 +- tests/test_memory_edge_cases.py | 9 ++++----- tests/test_prompts_critical.py | 2 +- tests/test_registry_critical.py | 2 +- tests/test_registry_edge_cases.py | 2 +- 13 files changed, 29 insertions(+), 30 deletions(-) diff --git a/agent/llm/deepseek.py b/agent/llm/deepseek.py index 36b86f8..65d6a67 100644 --- a/agent/llm/deepseek.py +++ b/agent/llm/deepseek.py @@ -51,7 +51,7 @@ class DeepSeekClient: logger.info(f"DeepSeek client initialized with model: {self.model}") - def complete( + def complete( # noqa: PLR0912 self, messages: list[dict[str, Any]], tools: list[dict[str, Any]] | None = None ) -> dict[str, Any]: """ diff --git a/agent/llm/ollama.py b/agent/llm/ollama.py index afd6a93..a0b377d 100644 --- a/agent/llm/ollama.py +++ b/agent/llm/ollama.py @@ -66,7 +66,7 @@ class OllamaClient: logger.info(f"Ollama client initialized with model: {self.model}") - def complete( + def complete( # noqa: PLR0912 self, messages: list[dict[str, Any]], tools: list[dict[str, Any]] | None = None ) -> dict[str, Any]: """ diff --git a/agent/prompts.py b/agent/prompts.py index 3ae658e..734e627 100644 --- a/agent/prompts.py +++ b/agent/prompts.py @@ -39,9 +39,8 @@ class PromptBuilder: for tool in self.tools.values() ) - def _format_episodic_context(self) -> str: + def _format_episodic_context(self, memory) -> str: """Format episodic memory context for the prompt.""" - memory = get_memory() lines = [] if memory.episodic.last_search_results: @@ -85,9 +84,8 @@ class PromptBuilder: return "\n".join(lines) - def _format_stm_context(self) -> str: + def _format_stm_context(self, memory) -> str: """Format short-term memory context for the prompt.""" - memory = get_memory() lines = [] if memory.stm.current_workflow: @@ -111,10 +109,8 @@ class PromptBuilder: return "\n".join(lines) - def _format_config_context(self) -> str: + def _format_config_context(self, memory) -> str: """Format configuration context.""" - memory = get_memory() - lines = ["CURRENT CONFIGURATION:"] if memory.ltm.config: for key, value in memory.ltm.config.items(): @@ -125,6 +121,7 @@ class PromptBuilder: def build_system_prompt(self) -> str: """Build the complete system prompt.""" + # Get memory once for all context formatting memory = get_memory() # Base instruction @@ -142,17 +139,17 @@ class PromptBuilder: tools_section = f"\nAVAILABLE TOOLS:\n{tools_desc}" if tools_desc else "" # Configuration - config_section = self._format_config_context() + config_section = self._format_config_context(memory) if config_section: config_section = f"\n{config_section}" # STM context - stm_context = self._format_stm_context() + stm_context = self._format_stm_context(memory) if stm_context: stm_context = f"\n{stm_context}" # Episodic context - episodic_context = self._format_episodic_context() + episodic_context = self._format_episodic_context(memory) # Important rules rules = """ diff --git a/app.py b/app.py index 9a04dd7..3e6849c 100644 --- a/app.py +++ b/app.py @@ -178,10 +178,10 @@ async def chat_completions(chat_request: ChatCompletionRequest): answer = agent.step(user_input) except LLMAPIError as e: logger.error(f"LLM API error: {e}") - raise HTTPException(status_code=502, detail=f"LLM API error: {e}") + raise HTTPException(status_code=502, detail=f"LLM API error: {e}") from e except Exception as e: logger.error(f"Agent error: {e}", exc_info=True) - raise HTTPException(status_code=500, detail="Internal agent error") + raise HTTPException(status_code=500, detail="Internal agent error") from e return JSONResponse( { diff --git a/infrastructure/api/qbittorrent/client.py b/infrastructure/api/qbittorrent/client.py index 68e5d51..61dc25b 100644 --- a/infrastructure/api/qbittorrent/client.py +++ b/infrastructure/api/qbittorrent/client.py @@ -282,7 +282,7 @@ class QBittorrentClient: } try: - response = self._make_request("POST", "/api/v2/torrents/delete", data=data) + self._make_request("POST", "/api/v2/torrents/delete", data=data) logger.info(f"Deleted torrent {torrent_hash}") return True diff --git a/infrastructure/api/tmdb/client.py b/infrastructure/api/tmdb/client.py index 5d33138..5cd9ce1 100644 --- a/infrastructure/api/tmdb/client.py +++ b/infrastructure/api/tmdb/client.py @@ -194,7 +194,6 @@ class TMDBClient: if "id" not in top_result or "media_type" not in top_result: raise TMDBAPIError("Invalid TMDB response structure") - tmdb_id = top_result["id"] media_type = top_result["media_type"] # Skip if not movie or TV show diff --git a/infrastructure/filesystem/file_manager.py b/infrastructure/filesystem/file_manager.py index 981d9da..c36303b 100644 --- a/infrastructure/filesystem/file_manager.py +++ b/infrastructure/filesystem/file_manager.py @@ -84,7 +84,9 @@ class FileManager: logger.error(f"Unexpected error setting path: {e}", exc_info=True) return {"error": "internal_error", "message": "Failed to set path"} - def list_folder(self, folder_type: str, path: str = ".") -> dict[str, Any]: + def list_folder( # noqa: PLR0911 + self, folder_type: str, path: str = "." + ) -> dict[str, Any]: """ List contents of a configured folder. @@ -165,7 +167,9 @@ class FileManager: logger.error(f"Unexpected error listing folder: {e}", exc_info=True) return {"error": "internal_error", "message": "Failed to list folder"} - def move_file(self, source: str, destination: str) -> dict[str, Any]: + def move_file( # noqa: PLR0911 + self, source: str, destination: str + ) -> dict[str, Any]: """ Move a file from one location to another. diff --git a/pyproject.toml b/pyproject.toml index c4eb365..afa94ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -100,7 +100,7 @@ exclude = [ ".qodo", ".vscode", ] -select = [ +lint.select = [ "E", "W", "F", "I", @@ -110,8 +110,8 @@ select = [ "PL", "UP", ] -ignore = ["PLR0913", "PLR2004", "TID252", "E501"] +lint.ignore = ["PLR0913", "PLR2004", "TID252", "E501"] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "tests/**/*.py" = ["PLC0415"] "conftest.py" = ["PLC0415"] diff --git a/tests/test_domain_edge_cases.py b/tests/test_domain_edge_cases.py index 44b0c59..2e9afee 100644 --- a/tests/test_domain_edge_cases.py +++ b/tests/test_domain_edge_cases.py @@ -85,7 +85,7 @@ class TestImdbIdEdgeCases: id2 = ImdbId("tt1234567") # Should be usable in set - s = {id1, id2} + _s = {id1, id2} # Test hashability # Depending on implementation, might be 1 or 2 items diff --git a/tests/test_memory_edge_cases.py b/tests/test_memory_edge_cases.py index 9153333..d320b00 100644 --- a/tests/test_memory_edge_cases.py +++ b/tests/test_memory_edge_cases.py @@ -390,9 +390,8 @@ class TestMemoryEdgeCases: """Should create directory if not exists.""" new_dir = temp_dir / "new" / "nested" / "dir" - # Create parent directories first - new_dir.mkdir(parents=True, exist_ok=True) - memory = Memory(storage_dir=str(new_dir)) + # Don't create the directory - let Memory do it + Memory(storage_dir=str(new_dir)) assert new_dir.exists() @@ -405,7 +404,7 @@ class TestMemoryEdgeCases: try: os.chmod(readonly_dir, 0o444) # This might raise or might work depending on OS - memory = Memory(storage_dir=str(readonly_dir)) + Memory(storage_dir=str(readonly_dir)) except (PermissionError, OSError): pass # Expected on some systems finally: @@ -512,7 +511,7 @@ class TestMemoryContextEdgeCases: """Should handle multiple init calls.""" _memory_ctx.set(None) - mem1 = init_memory(str(temp_dir)) + init_memory(str(temp_dir)) mem2 = init_memory(str(temp_dir)) # Second call should replace first diff --git a/tests/test_prompts_critical.py b/tests/test_prompts_critical.py index b08a94e..5f5697c 100644 --- a/tests/test_prompts_critical.py +++ b/tests/test_prompts_critical.py @@ -178,7 +178,7 @@ class TestPromptBuilderStructure: description = builder._format_tools_description() # Should have tool names and descriptions - for tool_name, tool in tools.items(): + for tool_name, _tool in tools.items(): assert tool_name in description # Should have parameters info assert "Parameters" in description or "parameters" in description diff --git a/tests/test_registry_critical.py b/tests/test_registry_critical.py index 13de63d..ec275e4 100644 --- a/tests/test_registry_critical.py +++ b/tests/test_registry_critical.py @@ -71,7 +71,7 @@ class TestToolSpecFormat: # Verify function has valid signature try: - sig = inspect.signature(tool.func) + inspect.signature(tool.func) # If we get here, signature is valid except Exception as e: pytest.fail(f"Tool {name} has invalid signature: {e}") diff --git a/tests/test_registry_edge_cases.py b/tests/test_registry_edge_cases.py index 78aae9b..9404bca 100644 --- a/tests/test_registry_edge_cases.py +++ b/tests/test_registry_edge_cases.py @@ -245,7 +245,7 @@ class TestMakeToolsEdgeCases: for tool in tools.values(): if "properties" in tool.parameters: - for prop_name, prop_schema in tool.parameters["properties"].items(): + for _prop_name, prop_schema in tool.parameters["properties"].items(): if "enum" in prop_schema: assert isinstance(prop_schema["enum"], list) assert len(prop_schema["enum"]) > 0