Repository navigation
Fix regression parsing out-of-order tables split by another table - #625
Open
faresrafat3 wants to merge 2 commits into
Open
faresrafat3 wants to merge 2 commits into
faresrafat3 wants to merge 2 commits into
Conversation
added 2 commits
October 1, 2026 15:37
Building the docs with `sphinx-build -n` reports many "py:class reference target not found" warnings for annotations such as collections.abc.Mapping, datetime.datetime and collections.abc.Sequence, because no intersphinx mapping is configured (see python-poetry#192). Add the sphinx.ext.intersphinx extension with the Python inventory. Warnings under -n drop from 55 to 31. The remainder are project-internal references (tomlkit.items.ItemT, tomlkit.container.Container, E, Encoder) that are not part of this change. Fixes python-poetry#192 (partially).
A document where a table has an out-of-order child, its concrete parent is
declared afterwards, and a later sibling child is separated by an unrelated
table was rejected with 'Key already exists', although tomllib and tomlkit
0.13.3/0.14.0/0.15.0 all accept it:
[tool.ruff]
[tool.ruff.lint.a]
[tool.ruff.lint]
[[tool.poetry.source]]
[tool.ruff.lint.b]
When a key is defined out of order, Container.item() returns an
OutOfOrderTableProxy rather than the Table itself, because the key maps to
several body positions. _validate_table_candidate compared the candidate
against that proxy with isinstance(existing, (Table, AoT)), which is False
for a proxy, so a valid table-vs-table extension was reported as a
table-vs-scalar type conflict and raised KeyAlreadyPresent.
Skip the type comparison when the existing entry is an out-of-order proxy;
its fragments are validated by the proxy itself.
Fixes python-poetry#571.
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.
tomlkit 0.15.1 rejects a valid document that
tomlliband tomlkit0.13.3/0.14.0/0.15.0 all accept:
All three ingredients are needed: an out-of-order child, its concrete parent
declared afterwards, and a later sibling child separated by an unrelated table.
Root cause
When a key is defined out of order,
Container._raw_appendrecords severalbody positions for it and
Container.item()then returns anOutOfOrderTableProxyinstead of theTable:_validate_table_candidatecompared the candidate against that proxy usingisinstance(proxy, (Table, AoT))isFalse— the proxy is a separate class —so a valid table-vs-table extension looked like a table-vs-scalar conflict and
raised
KeyAlreadyPresent. Traced at the failure point:Change
Skip the type comparison when the existing entry is an out-of-order proxy; its
fragments are already validated by the proxy. One condition, three lines of
comment.
Verification
The reported document now parses and round-trips byte-identically, and its
unwrap()matchestomllibexactly:Genuine duplicates are still rejected — checked explicitly, each raising:
[a]\n[a]\n[a]\nb=1\n[a]\n[a]\n[a.b]\n[a.b]\na=1\n[a]\n[a]\n[[a]]\n[a]\nb.c=1\n[a.b]\nTwo regression tests added to
tests/test_toml_document.py(the issue'sdocument, and a deeper variant without the array-of-tables). Full suite:
390 passed(388 before).