修复布尔配置值类型错误

- 解决 '_bool' object has no attribute 'lower' 错误
- 在 _get_bool_value 函数中添加类型检查
- 支持 YAML 布尔值和字符串布尔值的正确处理
- 确保程序在所有设备上正常运行
This commit is contained in:
qichi.liang
2026-01-03 21:52:21 +08:00
parent 6903ee6f0b
commit 3473a0a5ec

View File

@@ -78,7 +78,17 @@ def _get_int_value(yaml_config: Optional[Dict[str, Any]], env_key: str, yaml_pat
def _get_bool_value(yaml_config: Optional[Dict[str, Any]], env_key: str, yaml_path: List[str], default: bool) -> bool: def _get_bool_value(yaml_config: Optional[Dict[str, Any]], env_key: str, yaml_path: List[str], default: bool) -> bool:
"""获取布尔配置值""" """获取布尔配置值"""
value = _get_config_value(yaml_config, env_key, yaml_path, str(default).lower()) value = _get_config_value(yaml_config, env_key, yaml_path, str(default).lower())
return value.lower() == "true"
# 如果值已经是布尔类型,直接返回
if isinstance(value, bool):
return value
# 如果是字符串,转换为布尔值
if isinstance(value, str):
return value.lower() == "true"
# 其他类型转换为布尔值
return bool(value)
# 加载YAML配置 # 加载YAML配置