Fix dotted-key child replacement capturing following siblings - #575
Fix dotted-key child replacement capturing following siblings#575shleder wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Shleder <197753947+shleder@users.noreply.github.com>
davidpavlovschi
left a comment
There was a problem hiding this comment.
The reorder still misses later inline dotted assignments from a different top-level group. A newly rendered table/AoT header captures those assignments when there is no later same-group sibling to push it past.
Minimal reproduction on this head:
from tomlkit import parse
doc = parse("a.b = 1\nq.c = 2\n")
doc["a"]["b"] = {"x": 9}
output = doc.as_string()
assert doc.unwrap() == parse(output).unwrap()output is currently "\n[a.b]\nx = 9\nq.c = 2\n", so reparsing makes q.c a child of a.b. The same failure occurs with an AoT replacement. The move boundary needs to account for every later root-level inline dotted assignment that a rendered header would capture, not only entries whose k.key matches group_key.key. Please add a regression with only an unrelated group after the replaced entry; the current interleaving test also has a later a.c, which masks this case.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Fixed the requested unrelated-group boundary case in 6f91002. The exact
Added exact table, empty-table, and AoT regressions. Validation:
Full-tree Ruff reports only pre-existing style findings in the vendored |
Summary
Fixes #556.
When a dotted-key child such as
bina.b = 1is replaced with a table or array of tables through an out-of-order table proxy, that part begins rendering an[a.b]or[[a.b]]header at its original body position.Dotted siblings that follow it, such as
a.canda.d, then fall inside that table's scope, corrupting the document when serialized output is parsed again.This change detects the transition from an inline value to a table or AoT and moves the affected part after its inline same-group siblings, while keeping it before any subsequent same-group header part.
Because moving a body entry shifts other entries as well, the change rebuilds the complete key-to-index map and out-of-order metadata. This keeps unrelated plain keys, dotted groups, and other out-of-order tables correctly addressable and mutable. Proxy-derived state is rebuilt from the unchanged table parts after reordering.
Whitespace and trivia are preserved from the source document; the change does not add or remove blank lines.
Regression coverage includes:
Validation:
tests/test_toml_document.py— 78 passed;toml-testcorpus — 1058 passed;git diff --check— passed.Agent Drafting Metadata
sonnetfor architecture, review and test execution, andhaikuas the sole code-author rolesonnetis locally configured to route to Kimi K3;haikuis locally configured to route to Gemini 3.6 Flash