fix(ci): mypy python_version 3.10 → 3.12 修复 numpy stub 语法错误

根因:CI 的 mypy job 在 Python 3.13 下运行,安装的 numpy 2.x stub
使用 PEP 695 type 语句(3.12+ 语法),但 pyproject.toml 的
python_version="3.10" 让 mypy 按 3.10 语义解析,报
'Type statement is only supported in Python 3.12 and greater'。

修复:
- python_version 提升到 3.12(CI mypy job 实际跑 3.13,开发目标版本对齐)
- mypy/ruff 同步排除 gitignored 的 exchange_margin.py 本地脚本
- 顺带修复 market.py / test_screen.py 的 ruff format 漂移
This commit is contained in:
Justin Gu
2026-06-25 03:46:57 +08:00
parent e5bc1b1a16
commit 77104a32e3
3 changed files with 6 additions and 9 deletions
+4 -2
View File
@@ -23,7 +23,9 @@ packages = ["src/easy_tdx"]
[tool.mypy]
strict = true
python_version = "3.10"
python_version = "3.12"
# 跳过未跟踪的本地脚本(依赖外部 unified_config/sqlalchemy/requests,不属于库)
exclude = ["src/easy_tdx/exchange_margin\\.py"]
[[tool.mypy.overrides]]
module = ["pandas", "tabulate", "matplotlib", "matplotlib.*"]
@@ -44,7 +46,7 @@ ignore_missing_imports = true
[tool.ruff]
target-version = "py310"
line-length = 100
extend-exclude = ["*.pyi"]
extend-exclude = ["*.pyi", "src/easy_tdx/exchange_margin.py"]
[tool.ruff.lint]
select = ["E", "F", "I", "UP"]
+1 -3
View File
@@ -145,9 +145,7 @@ async def market_strength(
# 注:在协程内用 get_running_loop() 而非 get_event_loop()
# 后者在 Python 3.12+ 已弃用。
loop = asyncio.get_running_loop()
results = await loop.run_in_executor(
None, lambda: ranker.rank(universe=universe, top_n=top_n)
)
results = await loop.run_in_executor(None, lambda: ranker.rank(universe=universe, top_n=top_n))
records = [
{
+1 -4
View File
@@ -681,9 +681,7 @@ class TestStrengthRankerInit:
from easy_tdx.screen.strength import StrengthRanker
with patch("easy_tdx.screen.strength.resolve_vipdoc", return_value=Path("/fake")):
ranker = StrengthRanker(
preset="steady", w5=0.5, w20=0.3, w60=0.2, vol_adjusted=False
)
ranker = StrengthRanker(preset="steady", w5=0.5, w20=0.3, w60=0.2, vol_adjusted=False)
assert ranker._w5 == 0.5
assert ranker._w20 == 0.3
assert ranker._w60 == 0.2
@@ -695,4 +693,3 @@ class TestStrengthRankerInit:
with patch("easy_tdx.screen.strength.resolve_vipdoc", return_value=Path("/fake")):
ranker = StrengthRanker(preset="breakout")
assert ranker.preset == "breakout"