Python3 common patterns
Modify some codes in order to make them meet the Python3 common pattern. In this patch,I replace filter(lambda obj: test(obj),data) with[obj for obj in data if test(obj)] Change-Id: I68e76f91dc31aa0e00124c1eb76a0a1f0178cc44
This commit is contained in:
parent
258bd34b0f
commit
08f186a6e1
@ -49,7 +49,7 @@ def _rearrange_commands(cmds):
|
||||
"""
|
||||
|
||||
# Remove all 'noop' commands.
|
||||
cmds = list(filter(lambda c: not isinstance(c, commands.Noop), cmds))
|
||||
cmds = list([c for c in cmds if not isinstance(c, commands.Noop)])
|
||||
|
||||
state_cmd_idx = -1
|
||||
state_cmd = None
|
||||
|
@ -327,13 +327,9 @@ class RegularTask(Task):
|
||||
if self.reset_flag:
|
||||
execs = self.task_ex.executions
|
||||
else:
|
||||
execs = filter(
|
||||
lambda e: (
|
||||
e.accepted and
|
||||
e.state in [states.ERROR, states.CANCELLED]
|
||||
),
|
||||
self.task_ex.executions
|
||||
)
|
||||
execs = [e for e in self.task_ex.executions if
|
||||
(e.accepted and
|
||||
e.state in [states.ERROR, states.CANCELLED])]
|
||||
|
||||
for ex in execs:
|
||||
ex.accepted = False
|
||||
@ -598,7 +594,7 @@ class WithItemsTask(RegularTask):
|
||||
if list(filter(find_cancelled, self.task_ex.executions)):
|
||||
return True
|
||||
|
||||
execs = list(filter(lambda t: t.accepted, self.task_ex.executions))
|
||||
execs = list([t for t in self.task_ex.executions if t.accepted])
|
||||
count = self._get_with_items_count() or 1
|
||||
|
||||
# We need to make sure that method on_action_complete() has been
|
||||
@ -629,10 +625,8 @@ class WithItemsTask(RegularTask):
|
||||
def _get_accepted_executions(self):
|
||||
# Choose only if not accepted but completed.
|
||||
return list(
|
||||
filter(
|
||||
lambda x: x.accepted and states.is_completed(x.state),
|
||||
self.task_ex.executions
|
||||
)
|
||||
[x for x in self.task_ex.executions
|
||||
if x.accepted and states.is_completed(x.state)]
|
||||
)
|
||||
|
||||
def _get_unaccepted_executions(self):
|
||||
|
@ -165,7 +165,7 @@ class Workflow(object):
|
||||
# commands because workflow controller takes tasks that
|
||||
# completed within the period when the workflow was paused.
|
||||
cmds = list(
|
||||
filter(lambda c: not isinstance(c, commands.PauseWorkflow), cmds)
|
||||
[c for c in cmds if not isinstance(c, commands.PauseWorkflow)]
|
||||
)
|
||||
|
||||
# Since there's no explicit task causing the operation
|
||||
|
@ -136,7 +136,7 @@ class BaseTest(base.BaseTestCase):
|
||||
return True
|
||||
|
||||
filtered_items = list(
|
||||
filter(lambda item: _matches(item, **props), items)
|
||||
[item for item in items if _matches(item, **props)]
|
||||
)
|
||||
|
||||
found = len(filtered_items)
|
||||
|
@ -335,7 +335,7 @@ class DirectWorkflowSpec(WorkflowSpec):
|
||||
|
||||
@staticmethod
|
||||
def _remove_task_from_clause(on_clause, t_name):
|
||||
return list(filter(lambda tup: tup[0] != t_name, on_clause))
|
||||
return list([tup for tup in on_clause if tup[0] != t_name])
|
||||
|
||||
|
||||
class ReverseWorkflowSpec(WorkflowSpec):
|
||||
|
@ -41,7 +41,7 @@ def find_items(items, **props):
|
||||
|
||||
return True
|
||||
|
||||
filtered = list(filter(lambda item: _matches(item, **props), items))
|
||||
filtered = list([item for item in items if _matches(item, **props)])
|
||||
|
||||
if len(filtered) == 1:
|
||||
return filtered[0]
|
||||
|
@ -79,7 +79,7 @@ class SSHActionsTestsV2(base.TestCaseAdvanced):
|
||||
'floating_ips'
|
||||
)
|
||||
free_ips = list(
|
||||
filter(lambda fl_ip: fl_ip['instance_id'] is None, all_ips)
|
||||
[fl_ip for fl_ip in all_ips if fl_ip['instance_id'] is None]
|
||||
)
|
||||
|
||||
if free_ips:
|
||||
|
Loading…
Reference in New Issue
Block a user