From d19c89971ce22eee572f83c9b07d5c077950b118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Szata=C5=82owicz?= Date: Sat, 18 Oct 2025 11:31:14 +0200 Subject: [PATCH 1/3] quest --- app/main.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892f..807173e45 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,16 @@ -from typing import Callable +from typing import Callable, Any def cache(func: Callable) -> Callable: - # Write your code here - pass + results = {} + + def wrapper(*args: Any, **kwargs: Any) -> Any: + key = (args, tuple(sorted(kwargs.items()))) + if key not in results: + print("Calculating new result") + results[key] = func(*args, **kwargs) + else: + print("Getting from cache") + return results[key] + + return wrapper From 5e97b7589671075cb90d6ed8ba2b5b6f43c70c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Szata=C5=82owicz?= Date: Tue, 21 Oct 2025 09:45:55 +0200 Subject: [PATCH 2/3] Task corrected. Added functools.wraps and improved code structure. --- app/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 807173e45..6eb67d45c 100644 --- a/app/main.py +++ b/app/main.py @@ -1,9 +1,9 @@ from typing import Callable, Any - +from functools import wraps def cache(func: Callable) -> Callable: results = {} - + @wraps(func) def wrapper(*args: Any, **kwargs: Any) -> Any: key = (args, tuple(sorted(kwargs.items()))) if key not in results: From 907a00b794207314417e3f44be290bebf8b10003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Szata=C5=82owicz?= Date: Tue, 21 Oct 2025 10:03:50 +0200 Subject: [PATCH 3/3] Task corrected. Added functools.wraps and improved code structure. --- app/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/main.py b/app/main.py index 6eb67d45c..579d8cb66 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,10 @@ from typing import Callable, Any from functools import wraps + def cache(func: Callable) -> Callable: results = {} + @wraps(func) def wrapper(*args: Any, **kwargs: Any) -> Any: key = (args, tuple(sorted(kwargs.items())))