-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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' #1433
base: master
Are you sure you want to change the base?
'Solution' #1433
Conversation
app/main.py
Outdated
cache_data = {} | ||
|
||
def wrapper(*args) -> Callable: | ||
if args in cache_data.keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like calling keys()
not needed, as we already checking at dict keys
app/main.py
Outdated
pass | ||
cache_data = {} | ||
|
||
def wrapper(*args) -> Callable: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can return not only callable, because your functions can return any type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for your correction. I got it. I understood why exactly so and for what
app/main.py
Outdated
print("Getting from cache") | ||
return cache_data[args] | ||
|
||
cache_data[args] = func(*args) | ||
print("Calculating new result") | ||
return cache_data[args] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can try to simplify your solution to use only one return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Minor point about what decorator accept
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! 😎
No description provided.