Fix array of tables replacing a dotted key swallowing the next sibling (#542)#549
Open
HarperZ9 wants to merge 1 commit into
Open
Fix array of tables replacing a dotted key swallowing the next sibling (#542)#549HarperZ9 wants to merge 1 commit into
HarperZ9 wants to merge 1 commit into
Conversation
python-poetry#542) Assigning an AoT over a dotted key (e.g. `doc["a"] = aot(...)` where `a` came from `a.b = ...`) left the new `[[a]]` header in the dotted key's inline slot, so a following dotted sibling such as `c.d = 2` was rendered inside the array of tables and captured on round-trip. `_replace_at`'s `dotted_to_header` guard only recognised non-super Tables, not AoTs, so the reposition-before-inline-siblings path that already fixes the table case (python-poetry#513/python-poetry#524) never ran for arrays of tables. Extend the guard to AoT. Adds a regression test mirroring the table case and a changelog entry. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Fixes #542.
Assigning an array of tables over a dotted key swallows the following sibling on round-trip:
Before:
c.dis captured by[[a]], so it round-trips to{"a": [{"x": 9, "c": {"d": 2}}]}and the top-levelcis lost.Cause
In
Container._replace_at, thedotted_to_headerguard recognises only non-superTables, notAoTs. That guard drives the "drop the dotted prefix and move the new header past the inline entries (plain values and dotted keys) it would otherwise capture" path that already fixes the table case (#513 / #524). Because anAoTnever matched it, replacing a dotted key with an array of tables left the[[a]]header in the dotted key's inline slot, capturing the next dotted sibling.Fix
Extend
dotted_to_headerto also coverAoT(an array of tables always renders with its own[[header]], so it needs the same treatment as a non-super table). One-line logic change.After:
Round-trips to
{"c": {"d": 2}, "a": [{"x": 9}]}.Adds
test_replace_dotted_key_with_aot_keeps_following_sibling(mirrors the existing #513 table test) and a changelog entry. Full suite passes;ruff check/ruff formatare clean.