-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Recognize cached_property
as property
#4594
Conversation
Co-authored-by: Tiago Honorato <tiagohonorato1@gmail.com>
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.
Look good, might be even better if we put it in astroid (?) but this is mergeable.
pylint/checkers/utils.py
Outdated
except astroid.InferenceError: | ||
pass | ||
return False | ||
return _is_property(node) |
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.
Could this be a function of a FunctionDef
instance directly in astroid ?
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.
After thinking a bit more about it, I'm not sure anymore using _is_property
is the right call. If you look at astroid/bases.py, there are quite a few names that are assumed to be properties. It might add more false-positives then it removes.
I'll push a second commit to just add functools.cached_property
to _is_property_decorator
. That would be the safe choice. Please let me know what you think
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.
Sounds good, I never saw this POSSIBLE_PROPERTIES
const in astroid before.
cached_property
as property
Description
Supersedes #4144 originally authored by @tiagohonorato
Overriding a
property
withcached_property
currently results in aninvalid-overridden-method
error as the definition for property is too narrow. @hippo91 suggested to useastroid.bases._is_property
which seems to work well: #4023 (comment)https://docs.python.org/3/library/functools.html#functools.cached_property
Type of Changes
Related Issue
Closes #4023