Fix ParseError when a sub-table extends an array of tables out of order#498
Open
sarathfrancis90 wants to merge 1 commit into
Open
Fix ParseError when a sub-table extends an array of tables out of order#498sarathfrancis90 wants to merge 1 commit into
sarathfrancis90 wants to merge 1 commit into
Conversation
…ent after an unrelated table
When a sub-table header such as [fruit.apple.texture] follows the array
[[fruit]] with an unrelated table in between, the parser rebuilds it as a
fresh super table named "fruit" and tries to append it to the document,
colliding with the existing array of tables and raising
ParseError: Key "fruit" already exists.
even though the document is valid TOML 1.0.0. The contiguous form (no
intervening table) already worked because the sub-table is consumed while
the array element is still being parsed.
A sub-table header that refers to an existing array of tables extends the
array's last element, regardless of any tables defined in between, so merge
its contents into that element instead of treating it as a redefinition.
Defining a non-super table with the same name as an array (e.g. [fruit]
after [[fruit]]) is still a genuine conflict and continues to raise.
Fixes python-poetry#261
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 #261.
tomlkitraisesParseError: Key "fruit" already exists.on valid TOML when a sub-table header extends an array of tables with an unrelated table in between:The contiguous form (without
[potato]) already parses, because[fruit.apple.texture]gets consumed while the array element is still being parsed. Once an unrelated table breaks that up, the header is rebuilt as a fresh super table namedfruitand appended to the document, colliding with the existing array.A sub-table header naming an existing array of tables refers to the array's last element, so I merge its contents there instead of treating it as a redefinition. Defining a real table with an array's name (
[fruit]after[[fruit]]) is still a genuine conflict and keeps raising.One caveat worth flagging: on the round trip the out-of-order sub-table is normalized into the array element rather than kept at its original position. Byte-for-byte preservation isn't reachable here the way it is for plain tables — those lean on
OutOfOrderTableProxy, which is dict-shaped, whereas an array element has to round-trip back as a list. The data is correct and stable on re-dump; happy to dig into preserving the exact layout if you'd prefer.Added a regression test; full suite, ruff and mypy all pass.