Skip to content

Commit 8e1051f

Browse files
committed
Make invalid state unrepresantable
1 parent 604fa78 commit 8e1051f

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

src/towncrier/_writer.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,13 @@ def append_to_newsfile(
3232
raise ValueError("It seems you've already produced newsfiles for this version?")
3333

3434
with open(news_file, "w", encoding="utf8") as f:
35-
_write_news(f, header, start_string, content, prev_body)
35+
if header:
36+
f.write(header)
3637

38+
f.write(content)
3739

38-
def _write_news(f, header, start_string, new_content, old_body):
39-
"""
40-
Write complete news into *f*.
41-
"""
42-
if header:
43-
f.write(header)
44-
# If we have a header, we also have a start_string, because the header
45-
# is computed by splitting the file at start_string.
46-
f.write(f"\n\n{start_string}\n")
47-
48-
f.write(new_content)
49-
50-
if old_body:
51-
f.write(f"\n\n{old_body}")
40+
if prev_body:
41+
f.write(f"\n\n{prev_body}")
5242

5343

5444
def _figure_out_existing_content(news_file, start_string, single_file):
@@ -70,6 +60,6 @@ def _figure_out_existing_content(news_file, start_string, single_file):
7060

7161
t = content.split(start_string, 1)
7262
if len(t) == 2:
73-
return t[0].rstrip(), t[1].lstrip()
63+
return f"{t[0].rstrip()}\n\n{start_string}\n", t[1].lstrip()
7464

7565
return "", content.lstrip()

0 commit comments

Comments
 (0)