From 3849699e1058df673e1579beed0d42dfa156eac9 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 8 Apr 2020 14:04:51 +0200 Subject: [PATCH] ZOOKEEPER-3782: Replace filter() with list comprehension for returning list After Py3, `filter` return a `filter object` instead of `list object`, which causes ``` Traceback (most recent call last): File "zk-merge-pr.py", line 533, in main() File "zk-merge-pr.py", line 519, in main resolve_jira_issues(commit_title, merged_refs, jira_comment) File "zk-merge-pr.py", line 329, in resolve_jira_issues resolve_jira_issue(merge_branches, comment, jira_id) File "zk-merge-pr.py", line 312, in resolve_jira_issue jira_fix_versions = [get_version_json(v) for v in fix_versions] File "zk-merge-pr.py", line 312, in jira_fix_versions = [get_version_json(v) for v in fix_versions] File "zk-merge-pr.py", line 310, in get_version_json return filter(lambda v: v.name == version_str, versions)[0].raw TypeError: 'filter' object is not subscriptable ``` We can replace filter with list comprehension to fix it. Author: tison Reviewers: Enrico Olivelli Closes #1303 from TisonKun/ZOOKEEPER-3782 --- zk-merge-pr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zk-merge-pr.py b/zk-merge-pr.py index dc5549d9dfa..0118cba2c64 100644 --- a/zk-merge-pr.py +++ b/zk-merge-pr.py @@ -307,12 +307,12 @@ def resolve_jira_issue(merge_branches, comment, default_jira_id=""): fix_versions = fix_versions.replace(" ", "").split(",") def get_version_json(version_str): - return filter(lambda v: v.name == version_str, versions)[0].raw + return [v for v in versions if v.name == version_str][0].raw jira_fix_versions = [get_version_json(v) for v in fix_versions] - resolve = filter(lambda a: a['name'] == "Resolve Issue", asf_jira.transitions(jira_id))[0] - resolution = filter(lambda r: r.raw['name'] == "Fixed", asf_jira.resolutions())[0] + resolve = [a for a in asf_jira.transitions(jira_id) if a['name'] == "Resolve Issue"][0] + resolution = [r for r in asf_jira.resolutions() if r.raw['name'] == "Fixed"][0] asf_jira.transition_issue( jira_id, resolve["id"], fixVersions = jira_fix_versions, comment = comment, resolution = {'id': resolution.raw['id']})