-
-
Notifications
You must be signed in to change notification settings - Fork 476
feat: Replaced useless cached_property
with property
and moved to functools.cached_property
#2769
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
base: master
Are you sure you want to change the base?
Conversation
… `functools.cached_property`
See #2636 (comment) and #2636 (comment) |
Do you think is better to replace the two |
nvm, I missunderstood, you meant it already uses |
Keeping them as is it’s fine, it saves a function call because the data where cached_property is used is static, ie created_at, it’s bound to the id, and IDs cannot change, so calculating it everything it gets the property attr is not worth it, and it’s also not that necessary to be stored on a class attribute. |
discord/poll.py
Outdated
@@ -358,7 +358,7 @@ def __init__( | |||
self._expiry = None | |||
self._message = None | |||
|
|||
@utils.cached_property | |||
@property |
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.
would benefit imo from functools.cached_property
but wait for feedback
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.
This one doesn't appear to be a computationally intensive code, but let's wait further feedback.
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.
I just assumed utils.parse_time
had enough logic that would make sense to cache it but idk
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.
It’d be better if it stayed as a cached_property
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.
Yeah but use the functools one
discord/onboarding.py
Outdated
@@ -247,7 +247,7 @@ def _update(self, data: OnboardingPayload): | |||
self.enabled: bool = data["enabled"] | |||
self.mode: OnboardingMode = try_enum(OnboardingMode, data.get("mode")) | |||
|
|||
@cached_property | |||
@property | |||
def default_channels( |
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.
would benefit imo from functools.cached_property
but wait for feedback
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.
I agree on this one
Do I need to fix this based on suggestions? |
Yeah
|
Summary
Fixes #2660
Replaced all
cached_property
withproperty
orfunctools.cached_property
based on the solution mentioned in the issue.Information
examples, ...).
Checklist
type: ignore
comments were used, a comment is also left explaining why.