fix: don't reject an out-of-order super-table extended by a dotted key#565
Open
chuenchen309 wants to merge 1 commit into
Open
Conversation
`Container._validate_table_candidate` rejected valid TOML: when a deep header
like `[a.b.c]` makes `a.b` an implicit super-table, reopening `[a]` and
extending `a.b` via a dotted key (`b.z = 1`) was rejected with "Redefinition of
an existing table". No table is defined twice -- `a.b` only gains a new key --
and stdlib `tomllib` (the validity oracle the tests already use) accepts it,
producing `{'a': {'b': {'c': {}, 'z': 1}}}`.
The `if k.is_dotted(): raise` guard fired before the super-table recursion that
follows it, so it never got the chance to validate the subtree for a real
conflict. Only reject the dotted case when the existing entry is *not* a super
table; otherwise fall through to the existing recursion, which raises only on an
actual redefinition. The concrete-table case (`[a.b]` then `[a]` `b.z = 1`)
stays rejected, matching tomllib and the redefinition rejections from python-poetry#516/python-poetry#530.
Adds a regression test next to the sibling out-of-order tests; it is red before
the fix (ParseError) and green after. Full suite passes (372).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chuenchen309
force-pushed
the
fix/out-of-order-supertable-dotted-key
branch
from
July 17, 2026 05:14
834e3e8 to
d2c954e
Compare
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.
Summary
tomlkit rejects valid TOML on the
parse()path when an out-of-order table reopens an implicit super-table with a dotted key.[a.b.c]makesa.ban implicit super-table. Reopening[a]and extendinga.bwith a dotted key (b.z = 1) only adds a key to that super-table — it is not a redefinition — butContainer._validate_table_candidateraisesRedefinition of an existing table:stdlib
tomllib— the validity oracle the existing tests already cite (test_reject_out_of_order_dotted_*reference it) — accepts it.Cause: the
if k.is_dotted(): raiseguard in_validate_table_candidatefires before the super-table recursion right below it, so a dotted key whose existing side is a super-table never gets to the recursion that would check the subtree for a real conflict. The dotted rejection is only correct when the existing side is a concrete table.Fix: only take the dotted-key rejection when the existing entry is not a super-table; otherwise fall through to the existing recursion (which raises only on an actual redefinition). Two lines.
The concrete-table case (
[a.b]then[a]b.z = 1) stays rejected, matchingtomlliband the redefinition rejections added in #516 / #530 — all 27 out-of-order / redefinition tests still pass, and the full suite passes (372, including the new regression test). The target case now parses, round-trips byte-for-byte, andunwrap()matchestomllib.Regression test added next to the sibling out-of-order tests in
tests/test_toml_document.py; it is red before the fix (ParseError) and green after.Agent Drafting Metadata
tomllib, the fix, the regression test, and the full-suite run were verified before opening. I read the_validate_table_candidatelogic and confirmed the fix preserves every intended rejection (reject a table redefined after its parent table header #516/fix: reject out-of-order concrete+super table redefinitions at parse time #530) myself.