fix(types): 修复 CI mypy strict + ruff format 失败

mypy (13 errors → 0):
- portfolio/optimizer: register_optimizer 返回类型改为 Callable 装饰器签名
  (原标注 type[WeightOptimizer] 导致 4 个子类 Too many arguments)
- factor/engine: _datetime_to_int 用 isinstance 收窄替代 object→int 强转
- factor/analysis: 删多余 type:ignore(改由 mypy override 统一处理 scipy)
- backtest/orders, execution: np.sqrt 表达式用 float() 包裹消除 no-any-return
- MyTT.pyi: MACD 签名删除错误的 LOW/HIGH 参数(与 MyTT.py 实际签名对齐)
- pyproject: 新增 scipy mypy override (ignore_missing_imports)

ruff format: 8 个 test 文件格式化

验证: 564 passed, mypy 192 文件零错误, ruff check/format 全绿
This commit is contained in:
Justin Gu
2026-06-13 21:21:33 +08:00
parent 88638e82ad
commit 5fc398255d
15 changed files with 94 additions and 54 deletions
+9 -6
View File
@@ -1,5 +1,6 @@
# tests/unit/test_factor_transform.py
"""Test factor preprocessing functions."""
from __future__ import annotations
import numpy as np
@@ -20,12 +21,14 @@ def _make_cross_section(n_dates: int = 20, n_stocks: int = 30, seed: int = 42) -
rows = []
for d in range(n_dates):
for s in range(n_stocks):
rows.append({
"date": 20240101 + d,
"code": f"{s:06d}",
"momentum_20d": rng.normal(0.02, 0.05),
"volatility_20d": abs(rng.normal(0.02, 0.01)),
})
rows.append(
{
"date": 20240101 + d,
"code": f"{s:06d}",
"momentum_20d": rng.normal(0.02, 0.05),
"volatility_20d": abs(rng.normal(0.02, 0.01)),
}
)
df = pd.DataFrame(rows)
df.loc[0, "momentum_20d"] = 10.0
df.loc[1, "momentum_20d"] = -10.0