chore(lint): make the repository ruff-clean under the strict select

Clear the deferred full-repo lint backlog so the whole tree passes the strict
ruff select (E,W,F,I,B,UP,C4,SIM). Mechanical fixes dominate: import sorting,
pep585/604 annotations, dropped dead imports, and whitespace. The few semantic
changes are behavior-preserving: declare __all__ on the agent_utils and
alpha_vantage re-export hubs; expand 'from x import *' to explicit names; use
immutable tuple defaults instead of mutable list defaults; contextlib.suppress
for try/except/pass; and narrow an over-broad assertRaises.
This commit is contained in:
Yijia-Xiao
2026-06-14 16:38:36 +00:00
parent cbc5f67d42
commit e3bc872982
59 changed files with 315 additions and 293 deletions

View File

@@ -3,14 +3,12 @@
from __future__ import annotations
import os
from pathlib import Path
from unittest.mock import patch
import pytest
from tradingagents.llm_clients.api_key_env import PROVIDER_API_KEY_ENV, get_api_key_env
# ---- Mapping coverage -----------------------------------------------------
@@ -71,6 +69,7 @@ def test_case_insensitive_lookup():
def cli_utils(monkeypatch):
"""Import cli.utils with a fresh environment so module-level state is consistent."""
import importlib
import cli.utils as cli_utils_module
return importlib.reload(cli_utils_module)

View File

@@ -1,9 +1,10 @@
"""Unit tests for the LLM capability table."""
from dataclasses import FrozenInstanceError
import pytest
from tradingagents.llm_clients.capabilities import (
ModelCapabilities,
get_capabilities,
)
@@ -119,5 +120,5 @@ class TestDefault:
def test_capabilities_dataclass_is_frozen():
"""Capability rows are immutable so they can be safely shared."""
caps = get_capabilities("deepseek-chat")
with pytest.raises(Exception):
with pytest.raises(FrozenInstanceError):
caps.supports_tool_choice = False # type: ignore[misc]

View File

@@ -1,12 +1,9 @@
"""Test checkpoint resume: crash mid-analysis, re-run resumes from last node."""
import sqlite3
import tempfile
import unittest
from pathlib import Path
from typing import TypedDict
from langgraph.checkpoint.sqlite import SqliteSaver
from langgraph.graph import END, StateGraph
from tradingagents.graph.checkpointer import (

View File

@@ -24,7 +24,6 @@ from tradingagents.llm_clients.openai_client import (
_input_to_messages,
)
# ---------------------------------------------------------------------------
# _input_to_messages — the helper that handles list / ChatPromptValue / other
# (Gemini bot review note: non-list inputs must also work)

View File

@@ -1,15 +1,16 @@
"""Tests for TradingMemoryLog — storage, deferred reflection, PM injection, legacy removal."""
import pytest
import pandas as pd
from unittest.mock import MagicMock, patch
from tradingagents.agents.utils.memory import TradingMemoryLog
import pandas as pd
import pytest
from tradingagents.agents.managers.portfolio_manager import create_portfolio_manager
from tradingagents.agents.schemas import PortfolioDecision, PortfolioRating
from tradingagents.agents.utils.memory import TradingMemoryLog
from tradingagents.graph.propagation import Propagator
from tradingagents.graph.reflection import Reflector
from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.graph.propagation import Propagator
from tradingagents.agents.managers.portfolio_manager import create_portfolio_manager
_SEP = TradingMemoryLog._SEPARATOR

View File

@@ -6,7 +6,6 @@ news injected future articles), #993 (empty-after-filter returned a blank body).
"""
import time
from datetime import datetime
from unittest import mock
import pytest

View File

@@ -14,7 +14,7 @@ from unittest import mock
import pandas as pd
import pytest
from tradingagents.dataflows import stockstats_utils, interface
from tradingagents.dataflows import interface, stockstats_utils
from tradingagents.dataflows.config import set_config
from tradingagents.dataflows.symbol_utils import NoMarketDataError
@@ -33,9 +33,9 @@ class TestLoadOhlcvNoPoison(unittest.TestCase):
def test_empty_download_raises_and_does_not_cache(self):
empty = pd.DataFrame()
with mock.patch.object(stockstats_utils.yf, "download", return_value=empty) as dl:
with self.assertRaises(NoMarketDataError):
stockstats_utils.load_ohlcv("FAKE", "2026-01-01")
with mock.patch.object(stockstats_utils.yf, "download", return_value=empty), \
self.assertRaises(NoMarketDataError):
stockstats_utils.load_ohlcv("FAKE", "2026-01-01")
# Nothing should have been written to the cache.
self.assertEqual(os.listdir(self._tmp), [])

View File

@@ -18,8 +18,8 @@ def _resync_reloaded_modules():
doesn't leak across test modules.
"""
yield
import cli.utils
import cli.main
import cli.utils
importlib.reload(cli.utils)
importlib.reload(cli.main)

View File

@@ -4,7 +4,6 @@ Verifies the user-supplied base_url is required and honored, the key is optional
(keyless local default), Chat Completions (not the Responses API) is used, any
model name is accepted, and the env backend URL precedence (#978).
"""
import os
import pytest

View File

@@ -13,7 +13,6 @@ import pytest
from tradingagents.agents.utils.rating import RATINGS_5_TIER, parse_rating
from tradingagents.graph.signal_processing import SignalProcessor
# ---------------------------------------------------------------------------
# Heuristic parser
# ---------------------------------------------------------------------------

View File

@@ -27,7 +27,6 @@ from tradingagents.agents.schemas import (
)
from tradingagents.agents.trader.trader import create_trader
# ---------------------------------------------------------------------------
# Render functions
# ---------------------------------------------------------------------------

View File

@@ -6,8 +6,8 @@ import pytest
from tradingagents.dataflows.symbol_utils import (
NoMarketDataError,
normalize_symbol,
is_yahoo_safe,
normalize_symbol,
)

View File

@@ -6,7 +6,6 @@ Regressions for #988 (explicit single-vendor config still fell back to others),
were swallowed without a trace).
"""
import copy
import logging
import unittest
from unittest import mock
@@ -76,9 +75,9 @@ class VendorRoutingTests(unittest.TestCase):
# #989: primary errors + fallback no-data -> NO_DATA, but the failure
# must be visible in logs (broken primary not hidden).
set_config({"data_vendors": {"core_stock_apis": "yfinance,alpha_vantage"}})
with self._route({"yfinance": _raises(ValueError("boom")), "alpha_vantage": _no_data}):
with self.assertLogs("tradingagents.dataflows.interface", level="WARNING") as cm:
result = interface.route_to_vendor("get_stock_data", "AAPL", "2026-01-01", "2026-01-10")
with self._route({"yfinance": _raises(ValueError("boom")), "alpha_vantage": _no_data}), \
self.assertLogs("tradingagents.dataflows.interface", level="WARNING") as cm:
result = interface.route_to_vendor("get_stock_data", "AAPL", "2026-01-01", "2026-01-10")
self.assertIn("NO_DATA_AVAILABLE", result)
joined = "\n".join(cm.output)
self.assertIn("boom", joined) # the real error surfaced in logs