fix: 修正一个Maibot遇不到但是不能涵盖Toml整个格式的问题
This commit is contained in:
@@ -25,14 +25,11 @@ def _format_toml_value(obj: Any, threshold: int, depth: int = 0) -> Any:
|
|||||||
|
|
||||||
# 处理列表类型 (list 或 Array)
|
# 处理列表类型 (list 或 Array)
|
||||||
if isinstance(obj, (list, Array)):
|
if isinstance(obj, (list, Array)):
|
||||||
# 如果包含字典/表,视为 AoT 的列表形式或内联表数组,保持结构递归处理
|
# 如果是纯 list (非 tomlkit Array) 且包含字典/表,视为 AoT 的列表形式
|
||||||
if obj and isinstance(obj[0], (dict, Table)):
|
# 保持结构递归处理,避免转换为 Inline Table Array (因为 Inline Table 必须单行,复杂对象不友好)
|
||||||
|
if isinstance(obj, list) and not isinstance(obj, Array) and obj and isinstance(obj[0], (dict, Table)):
|
||||||
for i, item in enumerate(obj):
|
for i, item in enumerate(obj):
|
||||||
# 原地修改或递归处理
|
obj[i] = _format_toml_value(item, threshold, depth)
|
||||||
if isinstance(obj, list):
|
|
||||||
obj[i] = _format_toml_value(item, threshold, depth)
|
|
||||||
else:
|
|
||||||
_format_toml_value(item, threshold, depth)
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
# 决定是否多行:仅在顶层且长度超过阈值时
|
# 决定是否多行:仅在顶层且长度超过阈值时
|
||||||
@@ -67,4 +64,4 @@ def save_toml_with_format(data: Any, file_path: str, multiline_threshold: int =
|
|||||||
def format_toml_string(data: Any, multiline_threshold: int = 1) -> str:
|
def format_toml_string(data: Any, multiline_threshold: int = 1) -> str:
|
||||||
"""格式化 TOML 数据并返回字符串"""
|
"""格式化 TOML 数据并返回字符串"""
|
||||||
formatted = _format_toml_value(data, multiline_threshold) if multiline_threshold >= 0 else data
|
formatted = _format_toml_value(data, multiline_threshold) if multiline_threshold >= 0 else data
|
||||||
return tomlkit.dumps(formatted)
|
return tomlkit.dumps(formatted)
|
||||||
Reference in New Issue
Block a user