Skip to content

fix: deleting a key added before a table leaves a blank line behind - #579

Open
MildlyMeticulous wants to merge 1 commit into
python-poetry:masterfrom
MildlyMeticulous:fix/delete-key-leaves-blank-line
Open

fix: deleting a key added before a table leaves a blank line behind#579
MildlyMeticulous wants to merge 1 commit into
python-poetry:masterfrom
MildlyMeticulous:fix/delete-key-leaves-blank-line

Conversation

@MildlyMeticulous

Copy link
Copy Markdown

Summary

Adding a key to a document that begins with a table inserts a blank line to separate the new key from [a]. Deleting that key leaves the blank line behind, so the round trip doesn't restore the original document.

doc = tomlkit.parse("[a]\nx = 1\n")
doc["foo"] = 10
del doc["foo"]
doc.as_string()   # 0.15.1 gives '\n[a]\nx = 1\n', expected '[a]\nx = 1\n'

The separator was stored as the table's indent, so it outlived the key it was inserted for. It now trails the inserted item and is removed along with it. Repeated inserts still yield exactly one blank line, the behaviour asked for in #178, and there's a test covering that as well.

1053 tests pass.

Agent Drafting Metadata

  • Agent: Claude Code
  • Model: claude-opus-5
  • Notes: Found by round-trip differential testing against 0.15.1.

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