Just return empty lists instead of None
This commit is contained in:
parent
72766295c0
commit
d712a7eea2
1 changed files with 9 additions and 11 deletions
|
|
@ -6,7 +6,7 @@ import sys
|
||||||
|
|
||||||
def filter_change_block(
|
def filter_change_block(
|
||||||
change_lines: list[str], search: str, replace: str
|
change_lines: list[str], search: str, replace: str
|
||||||
) -> list[str] | None:
|
) -> list[str]:
|
||||||
removed_lines = []
|
removed_lines = []
|
||||||
added_lines = []
|
added_lines = []
|
||||||
phase = "minus"
|
phase = "minus"
|
||||||
|
|
@ -31,7 +31,7 @@ def filter_change_block(
|
||||||
return change_lines
|
return change_lines
|
||||||
|
|
||||||
if len(removed_lines) != len(added_lines):
|
if len(removed_lines) != len(added_lines):
|
||||||
return None
|
return []
|
||||||
|
|
||||||
kept_lines = []
|
kept_lines = []
|
||||||
for removed, added in zip(removed_lines, added_lines):
|
for removed, added in zip(removed_lines, added_lines):
|
||||||
|
|
@ -42,16 +42,16 @@ def filter_change_block(
|
||||||
kept_lines.append(f" {removed}")
|
kept_lines.append(f" {removed}")
|
||||||
|
|
||||||
if not kept_lines:
|
if not kept_lines:
|
||||||
return None
|
return []
|
||||||
|
|
||||||
return kept_lines
|
return kept_lines
|
||||||
|
|
||||||
|
|
||||||
def filter_hunk(
|
def filter_hunk(
|
||||||
hunk_lines: list[str], search: str, replace: str
|
hunk_lines: list[str], search: str, replace: str
|
||||||
) -> list[str] | None:
|
) -> list[str]:
|
||||||
if not hunk_lines:
|
if not hunk_lines:
|
||||||
return None, False
|
return []
|
||||||
|
|
||||||
header = hunk_lines[0]
|
header = hunk_lines[0]
|
||||||
body = hunk_lines[1:]
|
body = hunk_lines[1:]
|
||||||
|
|
@ -73,7 +73,7 @@ def filter_hunk(
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if not any(line.startswith(("+", "-")) for line in output_body):
|
if not any(line.startswith(("+", "-")) for line in output_body):
|
||||||
return None
|
return []
|
||||||
|
|
||||||
return [header] + output_body
|
return [header] + output_body
|
||||||
|
|
||||||
|
|
@ -120,12 +120,10 @@ def main() -> None:
|
||||||
kept_hunks = []
|
kept_hunks = []
|
||||||
for hunk_lines in section["hunks"]:
|
for hunk_lines in section["hunks"]:
|
||||||
filtered = filter_hunk(hunk_lines, search, replace)
|
filtered = filter_hunk(hunk_lines, search, replace)
|
||||||
if filtered:
|
|
||||||
if filtered != hunk_lines:
|
if filtered != hunk_lines:
|
||||||
left_out = True
|
left_out = True
|
||||||
|
if filtered:
|
||||||
kept_hunks.append(filtered)
|
kept_hunks.append(filtered)
|
||||||
elif hunk_lines:
|
|
||||||
left_out = True
|
|
||||||
|
|
||||||
if not kept_hunks:
|
if not kept_hunks:
|
||||||
left_out = True
|
left_out = True
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue