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' #1496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

'Solution' #1496

wants to merge 1 commit into from

Conversation

lukasz279
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great job on implementing the caching decorator! 🎉 Your code meets the task requirements and effectively handles caching for immutable arguments. While there are some suggestions for improvement, such as renaming variables for clarity and ensuring arguments are hashable, these are minor and don't impact the core functionality. Keep up the good work and consider these suggestions for future enhancements! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨



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

Choose a reason for hiding this comment

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

Consider renaming tuple_data to something more descriptive like cache_storage to better convey its purpose as a cache.

tuple_data = {}

def inner(*args, **kwargs) -> Any:
num = (args,)

Choose a reason for hiding this comment

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

The variable num is used to store the arguments as a tuple. However, if args contains mutable objects, this could lead to issues since mutable objects are not hashable. Ensure that the arguments are hashable or consider using a different approach to handle caching for mutable arguments.

num = (args,)
if num in tuple_data:
print("Getting from cache")
return tuple_data.get(num)

Choose a reason for hiding this comment

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

Using tuple_data.get(num) is correct, but you could also use tuple_data[num] since you have already checked for the key's existence in the dictionary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants