@@ -235,11 +235,11 @@ 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
241- The metadata holds information enough to remove the old unreleased and
242- where to place the new content
241+ The metadata governs how to remove the old unreleased section and where to place the
242+ new content.
243243
244244 Args:
245245 lines: The lines from the changelog
@@ -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,16 +270,14 @@ 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 ):
278+ if output_lines and output_lines [- 1 ].strip ():
279+ # Ensure at least one blank line between existing and new content.
280+ output_lines .append ("\n " )
283281 output_lines .append (new_content )
284282 return output_lines
285283
0 commit comments