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