fix: resolve all CI mypy (265→0) and ruff (26→0) errors

- pyproject.toml: add mypy overrides for pandas/tabulate/matplotlib stubs,
  disable strict checking for vendored MyTT library
- config.py: use cast() for dict[str, Any] .get() returns
- beichi.py: widen _calc_bi_force param to BI | XD, import XD
- backtest/cli.py: split combo/single strategy into separate typed variables
- backtest/combo.py: add bool_array() helper for numpy return types
- chanlun/analyser.py: type ignore for pandas row access, fix dict type arg
- unified.py: change fields param from object to Any
- ex/mac_client.py: add type args to list literals
- cli/cmd_offline.py: wrap int market as Market enum before API call
- cli/cmd_chanlun.py: fix dict type arg
- offline/write_*.py: explicit int() cast for struct.unpack returns
- MyTT.py: fix line-too-long comments, UP038 isinstance syntax
- tests: fix E712 (==False → ~mask), E741 (noqa), F841, import sorting
- ruff format applied across codebase

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
GitHub
2026-06-10 15:03:41 +08:00
co-authored by Claude Opus 4.8
parent 5aac7d3a39
commit 4dfd18050e
51 changed files with 548 additions and 335 deletions
+12 -10
View File
@@ -21,7 +21,7 @@ def parse_block_dat(data: bytes, filename: str = "") -> list["TdxBlock"]:
return []
pos = 384
(count,) = struct.unpack("<H", data[pos:pos+2])
(count,) = struct.unpack("<H", data[pos : pos + 2])
pos += 2
results: list[TdxBlock] = []
@@ -40,8 +40,8 @@ def parse_block_dat(data: bytes, filename: str = "") -> list["TdxBlock"]:
break
# 板块元数据 (9 字节名称 + 2 字节股票数 + 2 字节类型)
name_b = data[pos:pos+9]
stock_count, _type = struct.unpack("<HH", data[pos+9:pos+13])
name_b = data[pos : pos + 9]
stock_count, _type = struct.unpack("<HH", data[pos + 9 : pos + 13])
name = name_b.decode("gbk", errors="replace").strip("\x00")
# 股票代码区 (2800 字节,每只股票 7 字节)
@@ -51,17 +51,19 @@ def parse_block_dat(data: bytes, filename: str = "") -> list["TdxBlock"]:
actual_count = min(stock_count, 400)
for i in range(actual_count):
c_start = codes_start + i * 7
c_raw = data[c_start:c_start+7]
c_raw = data[c_start : c_start + 7]
code = c_raw.decode("ascii", errors="replace").strip("\x00")
if code:
codes.append(code)
results.append(TdxBlock(
name=name,
category=category,
count=stock_count,
codes=codes,
))
results.append(
TdxBlock(
name=name,
category=category,
count=stock_count,
codes=codes,
)
)
# 跳过整个 2813 字节的记录块
pos += 2813
+2 -7
View File
@@ -7,13 +7,10 @@
日线及以上(其余 category):4 字节 YYYYMMDD 整数
"""
from .._binary import unpack_from
def get_datetime_minute(
data: bytes | bytearray, pos: int
) -> tuple[int, int, int, int, int, int]:
def get_datetime_minute(data: bytes | bytearray, pos: int) -> tuple[int, int, int, int, int, int]:
"""解析分钟级时间戳(4 字节)。
Returns:
@@ -28,9 +25,7 @@ def get_datetime_minute(
return year, month, day, hour, minute, pos + 4
def get_datetime_day(
data: bytes | bytearray, pos: int
) -> tuple[int, int, int, int]:
def get_datetime_day(data: bytes | bytearray, pos: int) -> tuple[int, int, int, int]:
"""解析日期(4 字节 YYYYMMDD)。
Returns:
+3 -3
View File
@@ -25,9 +25,9 @@ _HEADER_FMT = "<IIIHH"
@dataclass(frozen=True)
class FrameHeader:
magic: int # 协议魔数,恒为 7654321
seq_id: int # ZipFlag(1B) + 请求 bytes 1-4 回显(3B)
method: int # 请求回显(1B) + 保留(1B) + Method(2B)
magic: int # 协议魔数,恒为 7654321
seq_id: int # ZipFlag(1B) + 请求 bytes 1-4 回显(3B)
method: int # 请求回显(1B) + 保留(1B) + Method(2B)
zipsize: int
unzipsize: int
+2 -1
View File
@@ -1,8 +1,9 @@
"""通达信行业配置文件 (tdxhy.cfg) 解析器。"""
def parse_tdxhy_cfg(content: bytes) -> dict[str, tuple[str, str]]:
"""解析 tdxhy.cfg 字节内容。
返回字典: { "code": (tdx_industry, sw_industry), ... }
"""
results = {}
+2 -3
View File
@@ -9,7 +9,6 @@
警告:此函数专为成交量设计,不可用于价格字段(pytdx Bug #3)。
"""
from .._binary import unpack_from
@@ -53,5 +52,5 @@ def _decode_volume(ivol: int) -> float:
def _pow2(exp: int) -> float:
if exp >= 0:
return float(1 << exp) if exp < 63 else 2.0 ** exp
return 1.0 / (1 << (-exp)) if -exp < 63 else 2.0 ** exp
return float(1 << exp) if exp < 63 else 2.0**exp
return 1.0 / (1 << (-exp)) if -exp < 63 else 2.0**exp