Skip to content
Open
Changes from 2 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
16 changes: 14 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from typing import Callable
from functools import wraps


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

@wraps(func)
def wrapper(*args, **kwargs) -> func:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional/low-severity: the wrapper's return annotation -> func is misleading (it references the function object, not the return value type). Consider using -> Any (from typing) or omitting the return annotation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The wrapper's return annotation -> func is misleading: func refers to the function object, not the return value type. Consider removing the annotation or using -> Any and importing Any from typing for clarity.

sorted_kwargs = tuple(sorted(kwargs.items()))
cle = (args, sorted_kwargs)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates the checklist item "Use descriptive and correct variable names." The variables resultats_executions and cle are not descriptive English names. Rename them to something clear like results_cache (or cache_store) and key so the intent is obvious and matches the checklist.

if cle not in resultats_executions:
print("Calculating new result")
resultats_executions[cle] = func(*args, **kwargs)
else:
print("Getting from cache")
return resultats_executions[cle]
return wrapper
Loading