Skip to content

Fix implicit-table extension after copying a document - #672

Open
AryanRG wants to merge 1 commit into
python-poetry:masterfrom
AryanRG:fix/copied-document-implicit-table
Open

AryanRG wants to merge 1 commit into
python-poetry:masterfrom
AryanRG:fix/copied-document-implicit-table

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 17, 2026

Copy link
Copy Markdown

Summary

Extending an implicit parent table after doc.copy() or copy.copy(doc) raises IndexError: list index out of range. The same operation succeeds on the original document:

import tomlkit

doc = tomlkit.parse("[a.b]\nx = 1\n").copy()
extension = tomlkit.table(True).add("c", {"y": 2})
doc.add("a", extension)

Container.__copy__ preserves the body and key map but drops the table-key history that implicit-table merging reads. Copy that history into the new container's separate list, preserving the existing shallow-copy semantics.

Four regression cases cover both copy entry points, with and without an intervening table. They check values, exact serialized placement, and reparsing. All four fail with the original implementation and pass with the fix.

Validation on macOS:

  • Python 3.11.16: 1,207 tests passed, including the pinned toml-test corpus.
  • Python 3.9.25: 1,206 passed, one skipped because stdlib tomllib requires Python 3.11+.
  • Ruff lint and format checks pass for both changed files; git diff --check passes.
  • Mypy reports the same 32 baseline errors in seven files; neither baseline nor patch is type-clean.
  • Independent GPT-6 Astra review approved the exact two-file patch with no P1/P2 findings, including additional copy, ordering, aliasing, and round-trip probes.

The complete OS/Python CI matrix and Poetry/poetry-core integration workflows were not run locally.

Agent Drafting Metadata

  • Agent: OpenAI Codex
  • Model: GPT-6.1 Sol (implementation); GPT-6 Astra (independent review).
  • Notes: AI assistance was used for investigation, implementation, regression tests, validation, and this PR description. GPT-6 Astra independently reviewed the exact patch before publication and returned APPROVE with no P1/P2 findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant