From 5ded808e54e63c38d44b80f511e9690f9a627c7d Mon Sep 17 00:00:00 2001 From: Vasilii Frolov Date: Tue, 10 Dec 2024 17:11:14 +0300 Subject: [PATCH] fix: violation of the DRY principle --- hello/hello_activity_choice.py | 39 ++++++++++------------------------ 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/hello/hello_activity_choice.py b/hello/hello_activity_choice.py index 56b7b7e6..2d9d9486 100644 --- a/hello/hello_activity_choice.py +++ b/hello/hello_activity_choice.py @@ -59,39 +59,22 @@ async def run(self, list: ShoppingList) -> str: ordered: List[str] = [] for item in list.items: if item.fruit is Fruit.APPLE: - ordered.append( - await workflow.execute_activity( - order_apples, - item.amount, - start_to_close_timeout=timedelta(seconds=5), - ) - ) + order_function = order_apples elif item.fruit is Fruit.BANANA: - ordered.append( - await workflow.execute_activity( - order_bananas, - item.amount, - start_to_close_timeout=timedelta(seconds=5), - ) - ) + order_function = order_bananas elif item.fruit is Fruit.CHERRY: - ordered.append( - await workflow.execute_activity( - order_cherries, - item.amount, - start_to_close_timeout=timedelta(seconds=5), - ) - ) + order_function = order_cherries elif item.fruit is Fruit.ORANGE: - ordered.append( - await workflow.execute_activity( - order_oranges, - item.amount, - start_to_close_timeout=timedelta(seconds=5), - ) - ) + order_function = order_oranges else: raise ValueError(f"Unrecognized fruit: {item.fruit}") + ordered.append( + await workflow.execute_activity( + order_function, + item.amount, + start_to_close_timeout=timedelta(seconds=5), + ) + ) return "".join(ordered)