From d712a7eea2de2ff4cebd5c7f84146e83b0335d02 Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Thu, 5 Mar 2026 21:09:06 +0100 Subject: [PATCH] Just return empty lists instead of None --- bin/mechanicaldiff.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/bin/mechanicaldiff.py b/bin/mechanicaldiff.py index 11fc6c5..03b4804 100755 --- a/bin/mechanicaldiff.py +++ b/bin/mechanicaldiff.py @@ -6,7 +6,7 @@ import sys def filter_change_block( change_lines: list[str], search: str, replace: str -) -> list[str] | None: +) -> list[str]: removed_lines = [] added_lines = [] phase = "minus" @@ -31,7 +31,7 @@ def filter_change_block( return change_lines if len(removed_lines) != len(added_lines): - return None + return [] kept_lines = [] for removed, added in zip(removed_lines, added_lines): @@ -42,16 +42,16 @@ def filter_change_block( kept_lines.append(f" {removed}") if not kept_lines: - return None + return [] return kept_lines def filter_hunk( hunk_lines: list[str], search: str, replace: str -) -> list[str] | None: +) -> list[str]: if not hunk_lines: - return None, False + return [] header = hunk_lines[0] body = hunk_lines[1:] @@ -73,7 +73,7 @@ def filter_hunk( i += 1 if not any(line.startswith(("+", "-")) for line in output_body): - return None + return [] return [header] + output_body @@ -120,12 +120,10 @@ def main() -> None: kept_hunks = [] for hunk_lines in section["hunks"]: filtered = filter_hunk(hunk_lines, search, replace) - if filtered: - if filtered != hunk_lines: - left_out = True - kept_hunks.append(filtered) - elif hunk_lines: + if filtered != hunk_lines: left_out = True + if filtered: + kept_hunks.append(filtered) if not kept_hunks: left_out = True