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

Recognize cached_property as property #4594

Merged
merged 3 commits into from
Jun 19, 2021

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Jun 18, 2021

Description

Supersedes #4144 originally authored by @tiagohonorato

Overriding a property with cached_property currently results in an invalid-overridden-method error as the definition for property is too narrow. @hippo91 suggested to use astroid.bases._is_property which seems to work well: #4023 (comment)

https://docs.python.org/3/library/functools.html#functools.cached_property

Type of Changes

Type
🐛 Bug fix

Related Issue

Closes #4023

Co-authored-by: Tiago Honorato <tiagohonorato1@gmail.com>
@cdce8p cdce8p added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jun 18, 2021
@cdce8p cdce8p added this to the 2.9.0 milestone Jun 18, 2021
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a 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.

except astroid.InferenceError:
pass
return False
return _is_property(node)
Copy link
Member

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 ?

Copy link
Member Author

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

Copy link
Member

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.

@coveralls
Copy link

coveralls commented Jun 18, 2021

Coverage Status

Coverage remained the same at 92.011% when pulling 654feba on cdce8p:fix-cached_property into fa144f6 on PyCQA:master.

@cdce8p cdce8p merged commit a1e1774 into pylint-dev:master Jun 19, 2021
@cdce8p cdce8p deleted the fix-cached_property branch June 19, 2021 10:50
@cdce8p cdce8p changed the title Better recognize property decorators Recognize cached_property as property Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(False positive) Method expected to be 'property', found it instead as 'method'.
3 participants