From 30e928fe1c219c3e48d52b2f741a35d698fdaef4 Mon Sep 17 00:00:00 2001 From: Alex Ovsienko Date: Wed, 17 Dec 2025 16:09:22 -0800 Subject: [PATCH] Fix possibly unbound Body by assigning preassigning them the else case and overriding them in the if case. The current case will work until eiether the has_chunk_header above or below the _process_diff function changes, and then it will cause runtime crash as one cannot concat string and None. Change-Id: I81737328f609e636bcee5087a2bc4aa96a6a6964 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7260374 Reviewed-by: Brian Egizi Reviewed-by: Gavin Mak Commit-Queue: Alex Ovsienko --- presubmit_diff.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/presubmit_diff.py b/presubmit_diff.py index 9bb32f562a..2e4e3db68a 100755 --- a/presubmit_diff.py +++ b/presubmit_diff.py @@ -84,11 +84,10 @@ def _process_diff(diff: str, src_root: str, dst_root: str) -> str: return "" has_chunk_header = HEADER_DELIMITER in diff + + header, body = diff, "" if has_chunk_header: header, body = diff.split(HEADER_DELIMITER, maxsplit=1) - else: - # Only the file mode changed. - header = diff norm_src = src_root.rstrip(os.sep) norm_dst = dst_root.rstrip(os.sep)