`ParseError` exception when handling TOML AoT
还没有人认领这个 Issue。
评估
调研方向
使用 issue 中的 TOML 文档重现该故障,然后根据提供的堆栈跟踪,跟踪经过 parser.py、container.py 和 items.py 的解析流程。当文档能够成功解析,且 tomlkit.dumps(parsed) 生成不包含 ParseError 的输出时,修复即完成。
由索引模型根据 Issue 内容生成。
描述
Hi!
I'm trying to parse a TOML document with tomlkit version 0.13.3 and getting this exception:
tomlkit.exceptions.ParseError: Key "fruits" already exists.
The document seems valid to me.
Code
import tomlkit
DOCUMENT = """
[[shops.aaa.fruits]]
id = "apple"
[[shops.bbb.fruits]]
id = "orange"
[[shops.aaa.fruits]]
id = "banana"
"""
parsed = tomlkit.parse(DOCUMENT)
print(tomlkit.dumps(parsed))
Expected
The document is parsed successfully.
Actual
Parsing fails with a ParseError.
Stacktrace
Traceback (most recent call last):
File "/Users/wfzx/dev/py/toml/venv/lib/python3.12/site-packages/tomlkit/parser.py", line 161, in parse
body.append(key, value)
File "/Users/wfzx/dev/py/toml/venv/lib/python3.12/site-packages/tomlkit/container.py", line 252, in append
current.append(k, v)
File "/Users/wfzx/dev/py/toml/venv/lib/python3.12/site-packages/tomlkit/items.py", line 1632, in append
_item = self._value[key]
~~~~~~~~~~~^^^^^
File "/Users/wfzx/dev/py/toml/venv/lib/python3.12/site-packages/tomlkit/container.py", line 652, in __getitem__
item = self.item(key)
^^^^^^^^^^^^^^
File "/Users/wfzx/dev/py/toml/venv/lib/python3.12/site-packages/tomlkit/container.py", line 476, in item
return OutOfOrderTableProxy(self, idx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/wfzx/dev/py/toml/venv/lib/python3.12/site-packages/tomlkit/container.py", line 846, in __init__
self._internal_container._raw_append(k, v)
File "/Users/wfzx/dev/py/toml/venv/lib/python3.12/site-packages/tomlkit/container.py", line 319, in _raw_append
raise KeyAlreadyPresent(key)
tomlkit.exceptions.KeyAlreadyPresent: Key "fruits" already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/wfzx/dev/py/toml/main.py", line 15, in <module>
parsed = tomlkit.parse(DOCUMENT)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/wfzx/dev/py/toml/venv/lib/python3.12/site-packages/tomlkit/api.py", line 93, in parse
return Parser(string).parse()
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/wfzx/dev/py/toml/venv/lib/python3.12/site-packages/tomlkit/parser.py", line 163, in parse
raise self.parse_error(ParseError, str(e)) from e
tomlkit.exceptions.ParseError: Key "fruits" already exists. at line 9 col 0
- 主要语言
- Python
- 星标
- 850
- 派生
- 163
- 平均合并
- 13 分钟
- 30 天内合并 PR
- 2
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-poetry/tomlkit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
python-poetry/tomlkit#546 · 2 条评论 ·
-
难度 3/5 1-2 天 新手友好度 68/100
python-poetry/tomlkit#603 ·
-
难度 3/5 1-2 天 新手友好度 52/100
python-poetry/tomlkit#580 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 72/100
python-poetry/tomlkit#577 ·
-
难度 5/5 一周以上 新手友好度 20/100
python-poetry/tomlkit#574 · 5 条评论 ·
查看 python-poetry/tomlkit 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 70/100
huggingface/Repo2RLEnv#163 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
难度 2/5 1-3 小时 新手友好度 70/100
NousResearch/hermes-agent#121143 ·