Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`ParseError` exception when handling TOML AoT

未关闭
#437 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
python
领域
tooling

调研方向

使用 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

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-poetry/tomlkit 的其他 Issue

查看 python-poetry/tomlkit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。