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 #1389

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

Solution #1389

wants to merge 1 commit into from

Conversation

yvespy
Copy link

@yvespy yvespy commented Nov 8, 2024

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 functions with immutable arguments. While there are some minor points to consider, such as ensuring args is hashable and correctly checking each element's type, these don't impact the core functionality. Keep up the great work and continue refining your skills! 😊

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

result = {}

def wrapper(*args) -> str:
if isinstance(args, (int, float, bool, str, tuple)):

Choose a reason for hiding this comment

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

The isinstance check is incorrect for args. args is a tuple, and this check will always return False. You should iterate over args and check each element instead.


def wrapper(*args) -> str:
if isinstance(args, (int, float, bool, str, tuple)):
if args in result:

Choose a reason for hiding this comment

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

Checking args in result will not work as expected because args is a tuple of arguments. You need to ensure that the tuple itself is hashable and can be used as a key in the dictionary.

return result[args]

new_result = func(*args)
result[args] = new_result

Choose a reason for hiding this comment

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

Ensure that args is hashable before using it as a key in the dictionary. If args contains unhashable elements, this will raise a TypeError.

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