From b386495520d1196d32e4ca59667b39f52b0699ef Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Barth Date: Tue, 3 Nov 2015 10:45:11 +0100 Subject: [PATCH] Use list comprehensions instead of filter() for easier moto/swf python 3.x compatibility --- moto/swf/models/__init__.py | 4 ++-- moto/swf/models/workflow_execution.py | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/moto/swf/models/__init__.py b/moto/swf/models/__init__.py index 8702bc374..4d70fbd0e 100644 --- a/moto/swf/models/__init__.py +++ b/moto/swf/models/__init__.py @@ -193,7 +193,7 @@ class SWFBackend(BaseBackend): candidates = [] for _task_list, tasks in domain.decision_task_lists.items(): if _task_list == task_list: - candidates += filter(lambda t: t.state == "SCHEDULED", tasks) + candidates += [t for t in tasks if t.state == "SCHEDULED"] if any(candidates): # TODO: handle task priorities (but not supported by boto for now) task = min(candidates, key=lambda d: d.scheduled_at) @@ -293,7 +293,7 @@ class SWFBackend(BaseBackend): candidates = [] for _task_list, tasks in domain.activity_task_lists.items(): if _task_list == task_list: - candidates += filter(lambda t: t.state == "SCHEDULED", tasks) + candidates += [t for t in tasks if t.state == "SCHEDULED"] if any(candidates): # TODO: handle task priorities (but not supported by boto for now) task = min(candidates, key=lambda d: d.scheduled_at) diff --git a/moto/swf/models/workflow_execution.py b/moto/swf/models/workflow_execution.py index 14523b079..cdc356ab5 100644 --- a/moto/swf/models/workflow_execution.py +++ b/moto/swf/models/workflow_execution.py @@ -202,17 +202,13 @@ class WorkflowExecution(object): @property def decision_tasks(self): - return filter( - lambda t: t.workflow_execution == self, - self.domain.decision_tasks - ) + return [t for t in self.domain.decision_tasks + if t.workflow_execution == self] @property def activity_tasks(self): - return filter( - lambda t: t.workflow_execution == self, - self.domain.activity_tasks - ) + return [t for t in self.domain.activity_tasks + if t.workflow_execution == self] def _find_decision_task(self, task_token): for dt in self.decision_tasks: @@ -294,7 +290,7 @@ class WorkflowExecution(object): # check decision types mandatory attributes # NB: the real SWF service seems to check attributes even for attributes list # that are not in line with the decisionType, so we do the same - attrs_to_check = filter(lambda x: x.endswith("DecisionAttributes"), dcs.keys()) + attrs_to_check = [d for d in dcs.keys() if d.endswith("DecisionAttributes")] if dcs["decisionType"] in self.KNOWN_DECISION_TYPES: decision_type = dcs["decisionType"] decision_attr = "{0}DecisionAttributes".format(decapitalize(decision_type))