Skip to content

Commit 404753b

Browse files
committed
Add compatibility shim for Python 3.9 and earlier.
1 parent 416a2c8 commit 404753b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/towncrier/_writer.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@
88

99
from __future__ import annotations
1010

11+
import sys
12+
1113
from pathlib import Path
14+
from typing import Any
15+
16+
17+
if sys.version_info < (3, 10):
18+
19+
def _newline_write_text(path: Path, content: str, **kwargs: Any) -> None:
20+
with path.open("w", **kwargs) as strm:
21+
strm.write(content)
22+
23+
else:
24+
25+
def _newline_write_text(path: Path, content: str, **kwargs: Any) -> None:
26+
path.write_text(content, **kwargs)
1227

1328

1429
def append_to_newsfile(
@@ -37,7 +52,8 @@ def append_to_newsfile(
3752
if top_line and top_line in prev_body:
3853
raise ValueError("It seems you've already produced newsfiles for this version?")
3954

40-
news_file.write_text(
55+
_newline_write_text(
56+
news_file,
4157
# If there is no previous body that means we're writing a brand new news file.
4258
# We don't want extra whitespace at the end of this new file.
4359
header + (content + prev_body if prev_body else content.rstrip() + "\n"),

0 commit comments

Comments
 (0)