Accept a table extending an out-of-order child of an out-of-order table - #583
Open
dchaudhari7177 wants to merge 1 commit into
Open
Conversation
[tool.ruff]
[tool.ruff.lint.a]
[tool.ruff.lint]
[[tool.poetry.source]]
[tool.ruff.lint.b]
raised `Key "lint" already exists` since 0.15.1, though tomllib and
0.15.0 accept it.
Extending an existing concrete table with a super table runs
_validate_table_candidate, which looks each candidate key up with
Container.item(). `lint` is itself split across two parts of `ruff`, so
item() returns an OutOfOrderTableProxy, not a Table -- and the
`isinstance(existing, (Table, AoT)) != isinstance(v, (Table, AoT))`
guard read that as a table being replaced by a plain value.
Give the proxy its own branch: compare against the merged view in its
internal container, and keep the duplicate-definition check by asking
whether any of its parts is concrete. The recursion now walks Containers
rather than Tables, which is all the checks ever used.
Fixes python-poetry#571
Contributor
|
why is this better or worse than the existing pull request #572? @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 #571.
Problem
tomlliband tomlkit 0.13.3 / 0.14.0 / 0.15.0 all accept this; 0.15.1 andmasterreject it.Cause
toolis out of order at the top level, so the last header extends an existing concretetoolfragment with a super table, which goes throughContainer._validate_table_candidate. That looks each candidate key up withContainer.item():lintis itself split across two parts ofruff— the implicit one from[tool.ruff.lint.a]and the concrete[tool.ruff.lint].item()therefore returns anOutOfOrderTableProxy, which is neither aTablenor anAoT, so the guard reads it as "a table is being replaced by a plain value" and raises.The intervening
[[tool.poetry.source]]matters only because without it the parser keeps all thetoolheaders in one fragment and this validation path is never reached. Any unrelated header reproduces it.Fix
Give the proxy its own branch, comparing against the merged view its internal container already holds. The duplicate-definition rule is preserved by asking whether any of the proxy's parts is concrete, so a genuine redefinition still raises.
The recursion now threads
Containers instead ofTables — every check in the function already went through.value, so this is a rename plus the new branch, and it is what lets the proxy's internal container be passed down.Tests
test_extend_out_of_order_child_of_out_of_order_table— the reported document parses, unwraps to the same shapetomllibproduces, and round-trips byte-for-byte.test_reject_duplicate_child_of_out_of_order_table— same shape but the last header repeats[tool.ruff.lint]; still aParseError.test_extend_out_of_order_child_at_depth— two more levels down, with two intervening headers.I also diffed tomlkit against
tomllibover the surrounding cases (duplicate[a],[a.b]twice across a split, a value/table conflict[a] x=1 … [a.x], dotted-key redefinition[a] b.c=1 … [a.b]): accept/reject now agrees withtomllibon all of them.Full suite passes (1054 tests).
🤖 Generated with Claude Code