Files
sanguo_vnpy_v2/sanguo_data/config.py
T
claude_dev 3422372948 fix(data): Task 1 review 修复(pycache清理+pytest.ini+错误处理)
- Fix 1: 移除误 commit 的 __pycache__ 文件
- Fix 2: 创建 pytest.ini 解决 PYTHONPATH 问题
- Fix 3: load_config 添加错误处理(FileNotFoundError + ValueError)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-05 11:50:30 +08:00

30 lines
813 B
Python

# sanguo_data/config.py
from dataclasses import dataclass
import yaml
@dataclass(frozen=True)
class DataConfig:
data_paths: dict
data_sources: dict
validation: dict
performance: dict
def load_config(path: str) -> DataConfig:
try:
with open(path, "r", encoding="utf-8") as f:
raw = yaml.safe_load(f)
except FileNotFoundError:
raise FileNotFoundError(f"配置文件不存在: {path}")
except yaml.YAMLError as e:
raise ValueError(f"YAML解析失败: {e}")
if not raw:
raise ValueError(f"配置文件为空: {path}")
return DataConfig(
data_paths=raw.get("data_paths", {}),
data_sources=raw.get("data_sources", {}),
validation=raw.get("validation", {}),
performance=raw.get("performance", {}),
)