Emptying a nested array of tables before an out-of-order super-table renders invalid TOML (0.15.2, since #567)

オープン
#690 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@ryanchou1994 がすでに取り組んでいます。

2026年11月2日 から。

  • #693 @ryanchou1994 による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

Start by running the reproduction in the issue: parse the [[a.b.c]] document, pop the element, and inspect the tomlkit.dumps output. The bug is in how an emptied array of tables is rendered when its super-table comes later in the document, which #567 changed; the issue says the parent commit of #567 produces valid output. Done when the output parses with both tomlkit.parse and tomllib.loads to {'a': {'b': {'c': []}, 'y': 1}}.

索引モデルが issue の本文から書いたものです。

説明

Versions tested: tomlkit 0.15.2 (tag a0b15eb), and master at d7def7d (2026-10-29); Python 3.12.

Reproduce:

import tomlkit

doc = tomlkit.parse("[[a.b.c]]\nx = 1\n\n[a]\ny = 1\n")
doc["a"]["b"]["c"].pop()
out = tomlkit.dumps(doc)
print(repr(out))
tomlkit.parse(out)

The input is valid TOML, and tomlkit parses it to {'a': {'b': {'c': [{'x': 1}]}, 'y': 1}}. After the pop, doc.unwrap() is {'a': {'b': {'c': []}, 'y': 1}}, as expected.

Observed: dumps returns 'a.b.c = []\n[a]\ny = 1\n', which declares a twice:

tomlkit.exceptions.ParseError: Redefinition of an existing table at line 3 col 0

tomllib.loads rejects it too: Cannot declare ('a',) twice (at line 2, column 3).

Expected: output that parses back to {'a': {'b': {'c': []}, 'y': 1}}, for example what tomlkit.dumps(doc.unwrap()) returns:

[a]
y = 1

[a.b]
c = []

Where it comes from: #567 renders an emptied array of tables as key = []. When the array sits under a super-table that is defined later in the document, the dotted key is emitted where the [[a.b.c]] header was, before [a]. On the parent commit of #567, the same steps produce output that parses. The same happens when [a] extends a.b with a dotted key, for example [[a.b.c]]\nx = 1\n[a]\nb.z = 1\n.

Related: #553, which #567 addressed in part, and #675, another failure after removing an element from an out-of-order table.

This came up while running generated tests on pairs of tomlkit pull requests that were open at the same time (#565 and #567). The reproduction above gives the same output on 0.15.2 and on master.

主要言語
Python
スター
864
フォーク
207
平均マージ
3日 22時間
マージ済み PR(30日)
25

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-poetry/tomlkit のほかの issue

python-poetry/tomlkit の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。