Skip to content

Prefix every line of a multiline comment with ##511

Merged
frostming merged 1 commit into
python-poetry:masterfrom
gaoflow:fix-449-multiline-comment
Jun 13, 2026
Merged

Prefix every line of a multiline comment with ##511
frostming merged 1 commit into
python-poetry:masterfrom
gaoflow:fix-449-multiline-comment

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #449.

comment("line one\nline two") only prepended # to the whole string, so every line after the first was emitted without a # and the document no longer re-parsed:

# line one
line two        # <- invalid

comment() now prefixes each line individually (a bare # for empty lines), so a multiline comment renders as a valid block of comment lines and round-trips. Single-line comments are unchanged.

@frostming

Copy link
Copy Markdown
Contributor

We hope that comments will always be single-line, and multi-line comments should be rejected, otherwise it will cause potential problems, such as:

a = 1
doc["a"].comment("line1\nline2")

will produce:

a = 1 # line1
#line2

The second line should not belong to the table item any more.

So, the right approach is:

doc["a"].comment("line1")
doc.append(comment("line2"))

Losing some flexibility, the code can more clearly reflect the actual structure.

comment() only prepended '# ' to the whole string, so a value with
embedded newlines rendered the second line onward without a '#' and
produced invalid TOML. Prefix each line individually (bare '#' for
empty lines). Fixes python-poetry#449.
@gaoflow gaoflow force-pushed the fix-449-multiline-comment branch from 27a79be to b7ab6bc Compare June 13, 2026 04:30
@frostming frostming merged commit 5b2b1ff into python-poetry:master Jun 13, 2026
25 checks passed
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.

Multiline comments

2 participants