Skip to content

Commit

Permalink
Use max() instead of sorted()
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed Jan 23, 2024
1 parent 8eb6814 commit f901713
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/rapids_pre_commit_hooks/copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f901713

Please sign in to comment.