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

Offen
#690 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

@ryanchou1994 arbeitet bereits daran.

Seit 02.11.2026.

  • #693 von @ryanchou1994 — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend

Rechercherichtung

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}}.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
864
Forks
207
Ø Merge
3 T. 23 Std.
Gemergte PRs (30 T.)
25

Entwicklungsumgebung

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python-poetry/tomlkit

Alle Issues in python-poetry/tomlkit

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.