From 6c48c4b23afd2b3eec7acb5ce4629678af5f80be Mon Sep 17 00:00:00 2001 From: Ruslan Misko Date: Fri, 29 Sep 2023 22:49:58 +0300 Subject: [PATCH 1/3] Solution --- app/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..2337b8a9 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,13 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_dict = {} + + def inner(*args: tuple) -> [list, int]: + if args not in cache_dict: + cache_dict[args] = func(*args) + print("Calculating new result") + return cache_dict[args] + print("Getting from cache") + return cache_dict[args] + return inner From 0850519afb65f11dfb5bdd34c52c8406ffcae503 Mon Sep 17 00:00:00 2001 From: Ruslan <135342393+MiskoRuslan@users.noreply.github.com> Date: Mon, 2 Oct 2023 19:08:12 +0300 Subject: [PATCH 2/3] Update main.py Fix not correct type anotation --- app/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 2337b8a9..58b81c1e 100644 --- a/app/main.py +++ b/app/main.py @@ -1,10 +1,11 @@ from typing import Callable +from typing import Any def cache(func: Callable) -> Callable: cache_dict = {} - def inner(*args: tuple) -> [list, int]: + def inner(*args: int) -> Any: if args not in cache_dict: cache_dict[args] = func(*args) print("Calculating new result") From a86d1d2c6fc02a7ce2b458295e7c2d2c21efa6ff Mon Sep 17 00:00:00 2001 From: Ruslan <135342393+MiskoRuslan@users.noreply.github.com> Date: Tue, 3 Oct 2023 00:33:02 +0300 Subject: [PATCH 3/3] Update main.py use only one 'return' --- app/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 58b81c1e..91ecfc83 100644 --- a/app/main.py +++ b/app/main.py @@ -9,7 +9,7 @@ def inner(*args: int) -> Any: if args not in cache_dict: cache_dict[args] = func(*args) print("Calculating new result") - return cache_dict[args] - print("Getting from cache") + else: + print("Getting from cache") return cache_dict[args] return inner