Summary
The print_suggestion() function in commit_check/util.py has a dead else branch that is never reached in practice.
Current Code
def print_suggestion(suggest: str | None) -> None:
"""Print suggestion to user
:param suggest: what message to print out
"""
if suggest:
print(
f"Suggest: {GREEN}{suggest}{RESET_COLOR} ",
end="",
)
else:
print(f"commit-check does not support {suggest} yet.")
raise SystemExit(1)
print("\n")
The Problem
- The function is only ever called when
suggest is truthy — see callers in _print_failure() (line 36) and print_errors() (line 293), both of which guard the call with `if check.get("suggest"):
- If the
else branch were somehow triggered, it would print "commit-check does not support None yet." — ugly and misleading.
- The dead code is confusing to readers and will show up in code coverage reports as uncovered.
Suggested Fix
Remove the unreachable else branch and simplify the function to handle only the happy path. Since the callers already guard against None/empty, the function signature can also be changed from str | None to str.
Files to Change
commit_check/util.py — the print_suggestion() function
- Optionally, update the docstring and type hint accordingly.
References
- Reported during codebase review of #485
- See also
util.py lines 307-316
Summary
The
print_suggestion()function incommit_check/util.pyhas a deadelsebranch that is never reached in practice.Current Code
The Problem
suggestis truthy — see callers in_print_failure()(line 36) andprint_errors()(line 293), both of which guard the call with `if check.get("suggest"):elsebranch were somehow triggered, it would print"commit-check does not support None yet."— ugly and misleading.Suggested Fix
Remove the unreachable
elsebranch and simplify the function to handle only the happy path. Since the callers already guard againstNone/empty, the function signature can also be changed fromstr | Nonetostr.Files to Change
commit_check/util.py— theprint_suggestion()functionReferences
util.pylines 307-316