Get rid of tuple return values
This commit is contained in:
parent
a19a77f105
commit
b54e8ab235
1 changed files with 13 additions and 22 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
|
||||||
) -> tuple[list[str] | None, bool]:
|
) -> list[str] | None:
|
||||||
removed_lines = []
|
removed_lines = []
|
||||||
added_lines = []
|
added_lines = []
|
||||||
phase = "minus"
|
phase = "minus"
|
||||||
|
|
@ -28,10 +28,10 @@ def filter_change_block(
|
||||||
re.sub(search, replace, line) for line in removed_lines
|
re.sub(search, replace, line) for line in removed_lines
|
||||||
]
|
]
|
||||||
if transformed_removed == added_lines:
|
if transformed_removed == added_lines:
|
||||||
return change_lines, False
|
return change_lines
|
||||||
|
|
||||||
if len(removed_lines) != len(added_lines):
|
if len(removed_lines) != len(added_lines):
|
||||||
return None, True
|
return None
|
||||||
|
|
||||||
kept_lines = []
|
kept_lines = []
|
||||||
for removed, added in zip(removed_lines, added_lines):
|
for removed, added in zip(removed_lines, added_lines):
|
||||||
|
|
@ -42,21 +42,20 @@ def filter_change_block(
|
||||||
kept_lines.append(f" {removed}")
|
kept_lines.append(f" {removed}")
|
||||||
|
|
||||||
if not kept_lines:
|
if not kept_lines:
|
||||||
return None, True
|
return None
|
||||||
|
|
||||||
return kept_lines, True
|
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
|
||||||
) -> tuple[list[str] | None, bool]:
|
) -> list[str] | None:
|
||||||
if not hunk_lines:
|
if not hunk_lines:
|
||||||
return None, False
|
return None, False
|
||||||
|
|
||||||
header = hunk_lines[0]
|
header = hunk_lines[0]
|
||||||
body = hunk_lines[1:]
|
body = hunk_lines[1:]
|
||||||
output_body: list[str] = []
|
output_body: list[str] = []
|
||||||
left_out = False
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(body):
|
while i < len(body):
|
||||||
|
|
@ -66,23 +65,17 @@ def filter_hunk(
|
||||||
while i < len(body) and body[i].startswith(("+", "-")):
|
while i < len(body) and body[i].startswith(("+", "-")):
|
||||||
block.append(body[i])
|
block.append(body[i])
|
||||||
i += 1
|
i += 1
|
||||||
kept_block, block_left_out = filter_change_block(
|
kept_block = filter_change_block(block, search, replace)
|
||||||
block, search, replace
|
|
||||||
)
|
|
||||||
if kept_block:
|
if kept_block:
|
||||||
output_body.extend(kept_block)
|
output_body.extend(kept_block)
|
||||||
else:
|
|
||||||
left_out = True
|
|
||||||
if block_left_out:
|
|
||||||
left_out = True
|
|
||||||
continue
|
continue
|
||||||
output_body.append(line)
|
output_body.append(line)
|
||||||
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, True
|
return None
|
||||||
|
|
||||||
return [header] + output_body, left_out
|
return [header] + output_body
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
|
@ -130,14 +123,12 @@ def main() -> None:
|
||||||
|
|
||||||
kept_hunks = []
|
kept_hunks = []
|
||||||
for hunk_lines in section["hunks"]:
|
for hunk_lines in section["hunks"]:
|
||||||
filtered, hunk_left_out = filter_hunk(
|
filtered = filter_hunk(hunk_lines, search, replace)
|
||||||
hunk_lines, search, replace
|
|
||||||
)
|
|
||||||
if filtered:
|
if filtered:
|
||||||
kept_hunks.append(filtered)
|
if filtered != hunk_lines:
|
||||||
else:
|
|
||||||
left_out = True
|
left_out = True
|
||||||
if hunk_left_out:
|
kept_hunks.append(filtered)
|
||||||
|
elif hunk_lines:
|
||||||
left_out = True
|
left_out = True
|
||||||
|
|
||||||
if not kept_hunks:
|
if not kept_hunks:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue