Repository navigation
Fix invalid TOML after deleting a nested dotted key in an inline table - #732
Merged
frostming merged 2 commits intoDec 4, 2026
Merged
Conversation
Deleting one of several dotted keys that share a two-level prefix inside
an inline table rendered the emptied part as `prefix = {}` next to the
remaining keys:
x = {a.b.c = 1, a.b.d = 2} -> x = {a.b = {}, a.b.d = 2}
which defines `a.b` twice. The proxy for `x["a"]["b"]` is looked up
through the `x["a"]` proxy, so `_remove_table()` removed the emptied part
only from that proxy's merged container, not from the real `a` part
that is rendered. Proxies now keep a reference to the proxy they were
looked up through and also remove the table from its real part.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
✅ Human Attestation: @zachyang374 attested this PR at commit
Later pushes to this PR stay attested. Attestation page |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frostming
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Deleting one of several dotted keys that share a two-level prefix inside an inline table wrote the emptied part as
prefix = {}next to the keys that are left:x["a"]["b"]is anOutOfOrderTableProxyover the twobparts, looked up through thex["a"]proxy. When__delitem__empties a part,_remove_table()removes it fromself._container, which here is the merged_internal_containerof thex["a"]proxy rather than the document. The emptiedbstays in the realapart, andInlineTable._render_dotted()renders it asa.b = {}.The fix:
OutOfOrderTableProxy.__getitem__now keeps a reference to the proxy it came from (_parent)._remove_table()also asks that parent to remove the table from the real part that holds it (_remove_child_table()). If that part becomes empty and other parts exist, it is removed in turn, through the same_remove_table(), so deeper prefixes work level by level.With this the example writes
x = { a.b.d = 2}, the same as the single-level casex = {b.c = 1, b.d = 2}already does. Proxies looked up from a real container have no parent, so their behavior does not change.Tests:
test_deleting_one_of_several_nested_dotted_keys_inside_inline_tablecovers deleting the first, last and middle key, deleting all of them (the table stays asa.b = {}), and a three-level prefix. All five cases fail on master and pass with the fix. The full suite passes (1489), pre-commit is clean, and mypy reports the same errors as on master. I also ran 20,000 random edit-and-dump runs against master and this branch: 6 runs that wrote invalid TOML on master pass here, and no run that passes on master fails here.Fixes #731
Duplicate Check
Agent Drafting Metadata