From f901713339b23589b47bcb7e5c1bdb1006bc20f3 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 23 Jan 2024 10:18:31 -0500 Subject: [PATCH] Use max() instead of sorted() --- src/rapids_pre_commit_hooks/copyright.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/rapids_pre_commit_hooks/copyright.py b/src/rapids_pre_commit_hooks/copyright.py index eb171be..ba84b72 100644 --- a/src/rapids_pre_commit_hooks/copyright.py +++ b/src/rapids_pre_commit_hooks/copyright.py @@ -157,18 +157,16 @@ def get_target_branch(repo, target_branch_arg=None): pass # Try newest branch-xx.yy - branches = sorted( - ( - (branch, (match.group("major"), match.group("minor"))) - for branch in repo.heads - if (match := BRANCH_RE.search(branch.name)) - ), - key=lambda i: i[1], - reverse=True, - ) try: - return branches[0][0] - except IndexError: + return max( + ( + (branch, (match.group("major"), match.group("minor"))) + for branch in repo.heads + if (match := BRANCH_RE.search(branch.name)) + ), + key=lambda i: i[1], + )[0] + except ValueError: pass # Appropriate branch not found