Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #1460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@


def cache(func: Callable) -> Callable:
# Write your code here
pass
data = {}

def wrapper(*args) -> None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wrapper function should have a return type that matches the return type of the func it decorates. Currently, it is set to None, which is incorrect. Consider changing it to Any or the specific return type of func.

if args in data:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using mutable types as dictionary keys can lead to issues since they are not hashable. Ensure that args are hashable (e.g., tuples of immutable types) when used as keys in the data dictionary.

print("Getting from cache")
return data[args]
else:
print("Calculating new result")
res_of_func = func(*args)
data[args] = res_of_func
return res_of_func

return wrapper
Loading