Skip to content

Commit 710407e

Browse files
committed
Fix newlines and add explanations
1 parent e13c567 commit 710407e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/towncrier/_writer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def append_to_newsfile(
3131
if top_line and top_line in prev_body:
3232
raise ValueError("It seems you've already produced newsfiles for this version?")
3333

34-
with open(news_file, "w", encoding="utf8") as f:
34+
# Leave newlines alone. This probably leads to inconsistent newlines,
35+
# because we've loaded existing content with universal newlines, but that's
36+
# the original behavior.
37+
with open(news_file, "w", encoding="utf8", newline="") as f:
3538
if header:
3639
f.write(header)
3740

@@ -55,6 +58,8 @@ def _figure_out_existing_content(news_file, start_string, single_file):
5558
# Non-existent files have no existing content.
5659
return "", ""
5760

61+
# If we didn't use universal newlines here, we wouldn't find *start_string*
62+
# which usually contains a `\n`.
5863
with open(news_file, encoding="utf8") as f:
5964
content = f.read()
6065

0 commit comments

Comments
 (0)