Fix spurious KeyAlreadyPresent on valid out-of-order child table (#571) - #592
Open
chiliec wants to merge 2 commits into
Open
Fix spurious KeyAlreadyPresent on valid out-of-order child table (#571)#592chiliec wants to merge 2 commits into
chiliec wants to merge 2 commits into
Conversation
…hon-poetry#571) _validate_table_candidate treated only Table/AoT as table-like. When a table is spread across out-of-order headers, its existing entry is an OutOfOrderTableProxy, so the isinstance(existing, (Table, AoT)) check was False while the candidate was a Table. The mismatch raised KeyAlreadyPresent for a document that tomllib and tomlkit <= 0.15.0 accept (a regression introduced by the concrete+super validation in 0.15.1). Recognise OutOfOrderTableProxy as table-like in the type-conflict check, and when the existing entry is a proxy recurse into each of its concrete table fragments so genuine duplicates are still rejected. Adds a regression test and a CHANGELOG entry. Full suite passes (1053 tests). Fixes python-poetry#571. Signed-off-by: Vladimir Babin <vovababin@gmail.com>
for more information, see https://pre-commit.ci
Contributor
|
explain why not #572 |
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
A regression in 0.15.1 rejects a valid document when a table has an out-of-order child, its concrete parent is declared afterwards, and another table separates a later sibling child:
tomlliband tomlkit 0.13.3 / 0.14.0 / 0.15.0 all accept it.Root cause
The concrete+super validation added in 0.15.1 (
_validate_table_candidate) treats onlyTable/AoTas table-like:When
lintis spread across out-of-order headers,current.value.item("lint")returns anOutOfOrderTableProxy, not aTable. So the left side isFalsewhile the candidate[tool.ruff.lint.b]is aTable(False != True), and valid input is reported as a type conflict.Fix
OutOfOrderTableProxyas table-like in the type-conflict check.Tablefragments (existing._tables) so a genuine duplicate is still detected, rather than rejecting outright.Real duplicates — including out-of-order ones like
[a.b]/[a]/[a.b]— remain rejected.Test
Adds
test_parse_accepts_out_of_order_child_with_intervening_table(the issue's exact document; asserts the parsed structure matchestomlliband the round-trip is byte-for-byte preserved). Also adds a CHANGELOG entry.Verification (local, Python 3.11)
Key "lint" already exists); with it, it passes.pytest tests/— 1053 passed, 0 failed (full suite incl. the BurntSushitoml-testconformance corpus), no regressions.tomllib.loads(...)anddumps(doc)reproduces the input exactly.ruff checkintroduces no new lint errors in the changed regions.