From 08c0b5929e015f9721c57c3d1051ca29e1296d8c Mon Sep 17 00:00:00 2001 From: Ronifue Date: Sat, 29 Nov 2025 16:16:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E4=B8=80=E4=B8=AAMaib?= =?UTF-8?q?ot=E9=81=87=E4=B8=8D=E5=88=B0=E4=BD=86=E6=98=AF=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=B6=B5=E7=9B=96Toml=E6=95=B4=E4=B8=AA=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/toml_utils.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/common/toml_utils.py b/src/common/toml_utils.py index c5a0824a..0c34f6ab 100644 --- a/src/common/toml_utils.py +++ b/src/common/toml_utils.py @@ -25,14 +25,11 @@ def _format_toml_value(obj: Any, threshold: int, depth: int = 0) -> Any: # 处理列表类型 (list 或 Array) if isinstance(obj, (list, Array)): - # 如果包含字典/表,视为 AoT 的列表形式或内联表数组,保持结构递归处理 - if obj and isinstance(obj[0], (dict, Table)): + # 如果是纯 list (非 tomlkit Array) 且包含字典/表,视为 AoT 的列表形式 + # 保持结构递归处理,避免转换为 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): - # 原地修改或递归处理 - if isinstance(obj, list): - obj[i] = _format_toml_value(item, threshold, depth) - else: - _format_toml_value(item, threshold, depth) + obj[i] = _format_toml_value(item, threshold, depth) 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: """格式化 TOML 数据并返回字符串""" formatted = _format_toml_value(data, multiline_threshold) if multiline_threshold >= 0 else data - return tomlkit.dumps(formatted) + return tomlkit.dumps(formatted) \ No newline at end of file