From 298e9aec65036779cf4d3ef502c4246497e3f97a Mon Sep 17 00:00:00 2001 From: XEDAB Date: Thu, 30 Jul 2026 06:05:32 +0800 Subject: [PATCH 1/2] fix: remove dead else branch in print_suggestion() (#486) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复issue486的问题,删掉了已经判断过而不可能进入的print_suggestion函数中的else分支,测试脚本已一并改动 (Machine translation / 机器翻译) Removed the unreachable else branch in print_suggestion() that could never be entered since all callers already guard with a truthy check. Updated the type hint from str | None to str, and removed the corresponding test. Close #486 --- commit_check/util.py | 5 +---- tests/util_test.py | 9 --------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/commit_check/util.py b/commit_check/util.py index af68cf07..b741467b 100644 --- a/commit_check/util.py +++ b/commit_check/util.py @@ -301,7 +301,7 @@ def print_error_message(check_type: str, error: str, reason: str): print(error) -def print_suggestion(suggest: str | None) -> None: +def print_suggestion(suggest: str) -> None: """Print suggestion to user :param suggest: what message to print out """ @@ -310,7 +310,4 @@ def print_suggestion(suggest: str | None) -> None: f"Suggest: {GREEN}{suggest}{RESET_COLOR} ", end="", ) - else: - print(f"commit-check does not support {suggest} yet.") - raise SystemExit(1) print("\n") diff --git a/tests/util_test.py b/tests/util_test.py index 2a106b00..33651195 100644 --- a/tests/util_test.py +++ b/tests/util_test.py @@ -605,15 +605,6 @@ def test_print_suggestion(self, capfd): stdout, _ = capfd.readouterr() assert "Suggest:" in stdout - @pytest.mark.benchmark - def test_print_suggestion_exit1(self, capfd): - # Must exit with 1 when "" passed - with pytest.raises(SystemExit) as e: - print_suggestion("") - assert e.value.code == 1 - stdout, _ = capfd.readouterr() - assert "commit-check does not support" in stdout - class TestGetGitConfigValue: """Tests for get_git_config_value utility function.""" From 75032a316392edfe6c5183ed6520e374f7555739 Mon Sep 17 00:00:00 2001 From: XEDAB Date: Thu, 30 Jul 2026 12:28:32 +0800 Subject: [PATCH 2/2] fix: resolve mypy type error in print_suggestion call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了mypy提到的错误,虽然本来也能跑,但现在_print_failure最后的print_suggestion传入的参数固定为str了 Fix the mypy error: the argument passed to print_suggestion in _print_failure is now guaranteed to be str (still works at runtime, just shuts up the type checker). --- commit_check/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commit_check/util.py b/commit_check/util.py index b741467b..f0be979a 100644 --- a/commit_check/util.py +++ b/commit_check/util.py @@ -27,7 +27,7 @@ def _print_failure( print_error_header() print_error_message(check["check"], check.get("error", ""), actual) if check.get("suggest"): - print_suggestion(check.get("suggest")) + print_suggestion(check["suggest"]) def get_branch_name() -> str: