# HG changeset patch # User Mads Kiilerich # Date 2020-02-04 03:07:44 # Node ID e68c0cd1647d85fd2f8f467593f4ba8740f43ef8 # Parent 7d5dfe117d0f36d241423128c4bbb6e5333034db pull-request: refactor iteration version bump Avoid relying on exceptions thrown when re.match fails ... and thus please pytype and make the code better. diff --git a/kallithea/model/pull_request.py b/kallithea/model/pull_request.py --- a/kallithea/model/pull_request.py +++ b/kallithea/model/pull_request.py @@ -362,11 +362,11 @@ class CreatePullRequestIterationAction(o infos.append(_('No changes found on %s %s since previous iteration.') % (org_ref_type, org_ref_name)) # TODO: fail? - try: - title, old_v = re.match(r'(.*)\(v(\d+)\)\s*$', title).groups() - v = int(old_v) + 1 - except (AttributeError, ValueError): - v = 2 + v = 2 + m = re.match(r'(.*)\(v(\d+)\)\s*$', title) + if m is not None: + title = m.group(1) + v = int(m.group(2)) + 1 self.create_action.title = '%s (v%s)' % (title.strip(), v) # using a mail-like separator, insert new iteration info in description with latest first