Merge an out-of-order fragment that extends an AoT element - #584
Open
dchaudhari7177 wants to merge 1 commit into
Open
Merge an out-of-order fragment that extends an AoT element#584dchaudhari7177 wants to merge 1 commit into
dchaudhari7177 wants to merge 1 commit into
Conversation
[[y.a]]
[b.d.x]
[[y.a.c]]
parses and round-trips, but doc["y"] or doc.unwrap() raised
`Key "a" already exists`.
`[b.d.x]` makes `y` out of order, so its parts go through
OutOfOrderTableProxy. The last header extends the last element of the
existing `y.a` array, which means the second `a` fragment arrives as an
implicit super table rather than as another AoT.
_merge_aot_fragment only recognised AoT + AoT, returned None, and
_raw_append then refused the duplicate key.
Handle the super-table shape too: copy the array's last element, merge
the fragment's body into the copy, and present a new AoT. Copying keeps
the fragments the document renders from untouched, as the AoT + AoT path
already does.
Fixes python-poetry#577
Contributor
|
why is this better or worse than the existing pull request #578? @dchaudhari7177 you should likely have your bot check for already-open pull requests before creating new ones |
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 #577.
Problem
tomllibreads this as{"y": {"a": [{"c": [{}]}]}, "b": {"d": {"x": {}}}}. Parsing and rendering are fine; only the read path fails.Cause
[b.d.x]splitsy, so reading it builds anOutOfOrderTableProxyover the twoyfragments. The final header extends the last element of the existingy.aarray rather than appending a new element, so the secondafragment arrives at the proxy as an implicit super table holdingc— not as anotherAoT._merge_aot_fragmentonly handlesAoT+AoT. It returnedNonefor the super-table shape, the caller fell through to_raw_append, and that refusedaas a duplicate key.Fix
Handle the super-table shape in the same place: copy the array's last element, merge the fragment's body into the copy, and hand back a new
AoT. Copying is what keeps the fragments the document renders from untouched — the same reason the existingAoT+AoTpath builds a newAoTinstead of mutating one.The guard stays narrow: only a super table (never a concrete
[y.a]redefinition) and only when the array actually has an element, so genuine duplicates still raise.Tests
test_out_of_order_table_merges_aot_element_extension— the reported document, with values on both sides, checking round-trip,unwrap()against thetomllibshape, and indexed access.test_out_of_order_table_extends_last_of_several_aot_elements— two elements before the split, confirming the extension lands on the last one only.I also checked the neighbouring shapes against
tomllib(a plain out-of-order AoT split,[y.a.c]as a plain table rather than an AoT, and two[[y.a.c]]headers separated by another table); all agree.Full suite passes (1053 tests).
🤖 Generated with Claude Code