Skip to content
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

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

Closed
staykotzenov opened this issue Jan 12, 2021 · 2 comments · Fixed by #4594
Closed
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors

Comments

@staykotzenov
Copy link

staykotzenov commented Jan 12, 2021

Steps to reproduce

  1. Creating a base class with a @property decorator on one of it`s field methods.
  2. Inheriting the base class in a child class and overriding the property method, this time with a @cached_property decorator.
# test.py
class Test():

    def __init__(self, smth):
        self.smth=smth

    @property
    def test_property(self):
        return 5
import functools
from test import Test

#child.py
class Child(Test):

    @functools.cached_property
    def test_property(self):
        return super().test_property + 5

Please refer to image below

Current behavior

Error message is triggered.
Method 'test_property' was expected to be 'property', found it instead as 'method'

Expected behavior

No error should be displayed, since @cached_property should still be a property

pylint --version output

pilyint 2.5.2
astroid 1.4.1
Python 3.8.0 (default, Nov 23 2019, 05:49:00)
[GCC 8.3.0]

@hippo91
Copy link
Contributor

hippo91 commented Jan 30, 2021

@staykotzenov thanks for the report. I can reproduce it with this smaller snippet:

import functools
class Test():
    @property
    def test_property(self):
        return 5


class Child(Test):
    @functools.cached_property
    def test_property(self):
        return super().test_property + 5

Of course if the test_property of the child class is decorated with @property then the message is not emitted.

@hippo91
Copy link
Contributor

hippo91 commented Jan 30, 2021

To those willing to fix this issue, it seems that the test inferred.name == 'property' inside the _is_property_decorator function of the checkers/utils.py is probably to restrictive.
The use of the _is_property function of the astroid's bases.py module is probably more adapted here.

@hippo91 hippo91 added Bug 🪲 Good first issue Friendly and approachable by new contributors False Positive 🦟 A message is emitted but nothing is wrong with the code labels Jan 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Help wanted 🙏 Outside help would be appreciated, good for new contributors label Mar 2, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors
Projects
None yet
3 participants