Skip to content

Commit f8c617e

Browse files
refactor(changelog): Simplify incremental_build
- Specify what output_lines and lines are lists of, namely strings. - Remove unnecessary test of whether latest_version_position is an int since x != None for any integer x. - Replace two consecutive list.append calls with a single list.extend call.
1 parent 186de51 commit f8c617e

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

commitizen/changelog.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def get_metadata(filepath: str) -> Dict:
235235
}
236236

237237

238-
def incremental_build(new_content: str, lines: List, metadata: Dict) -> List:
238+
def incremental_build(new_content: str, lines: List[str], metadata: Dict) -> List[str]:
239239
"""Takes the original lines and updates with new_content.
240240
241241
The metadata governs how to remove the old unreleased section and where to place the
@@ -253,7 +253,7 @@ def incremental_build(new_content: str, lines: List, metadata: Dict) -> List:
253253
unreleased_end = metadata.get("unreleased_end")
254254
latest_version_position = metadata.get("latest_version_position")
255255
skip = False
256-
output_lines: List = []
256+
output_lines: List[str] = []
257257
for index, line in enumerate(lines):
258258
if index == unreleased_start:
259259
skip = True
@@ -270,13 +270,8 @@ def incremental_build(new_content: str, lines: List, metadata: Dict) -> List:
270270
if skip:
271271
continue
272272

273-
if (
274-
isinstance(latest_version_position, int)
275-
and index == latest_version_position
276-
):
277-
278-
output_lines.append(new_content)
279-
output_lines.append("\n")
273+
if index == latest_version_position:
274+
output_lines.extend([new_content, "\n"])
280275

281276
output_lines.append(line)
282277
if not isinstance(latest_version_position, int):

0 commit comments

Comments
 (0)