Skip to content

fix: keep add_line comments from swallowing the closing bracket - #606

Closed
00200200 wants to merge 1 commit into
python-poetry:masterfrom
00200200:fix/add-line-comment-closes-array
Closed

00200200 wants to merge 1 commit into
python-poetry:masterfrom
00200200:fix/add-line-comment-closes-array

Conversation

@00200200

Copy link
Copy Markdown

Fixes #580

Array.add_line(..., comment=...) builds a compact array. The last item is a # comment with an empty trail, so as_string() glued the closing ] onto that comment:

[
    "foo", # bar]

That is not valid TOML. If the last compact item is a comment without a newline, a newline is inserted before ]. The existing add_line tests that already end with a newline are unchanged.

Agent Drafting Metadata

  • Agent: Cursor
  • Model: Grok 4.6
  • Notes: Helped write the regression test and the compact-render guard. I reproduced the invalid TOML on main first, then applied the fix.

Tests

pytest tests/test_items.py -k add_line

add_line with a comment left the array in compact rendering, so the
trailing # comment ran into the final ]. Insert a newline before that
bracket so the result is valid TOML.
@00200200

Copy link
Copy Markdown
Author

Closing this — I missed the existing PRs already covering #580. Sorry for the noise.

@00200200 00200200 closed this Sep 18, 2026
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.

Array.add_line() doesn't serialize as documented (or expected) and can even produce syntactically invalid TOML

1 participant