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

False Positive W0143-comparison-with-callable when using derived property descriptors #9722

Open
couteau opened this issue Jun 10, 2024 · 0 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@couteau
Copy link

couteau commented Jun 10, 2024

Bug description

Pylint reports a W0143 warning when comparing an attribute that is a descriptor to a constant, but only when the descriptor class has more than one level of class ancestry. As the example shows, it doesn't matter what those descriptors do -- just deriving two levels of child classes from the builtin property class without adding or modifying the functionality triggers the bug.

class my_prop(property):
    pass


class my_prop2(my_prop):
    pass


class Test:
    def __init__(self) -> None:
        self._prop = None
        self._prop2 = None

    @my_prop
    def prop(self) -> str:
        return self._prop

    @my_prop2
    def prop2(self) -> str:
        return self._prop2


c = Test()

if c.prop == "test": # no warning here
    pass

if c.prop2 == "test": # W0143 warning here
    pass

Configuration

No response

Command used

pylint -d C,R test.py

Pylint output

************* Module test
test.py:28:3: W0143: Comparing against a callable, did you omit the parenthesis? (comparison-with-callable)

------------------------------------------------------------------
Your code has been rated at 9.41/10

Expected behavior

I expect pylint to recognize a descriptor, even when that descriptor may have multiple ancestors

Pylint version

pylint 3.2.2
astroid 3.2.2
Python 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:34:54) [Clang 16.0.6 ]

OS / Environment

macOS Sonoma

Additional dependencies

No response

@couteau couteau added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 10, 2024
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jun 11, 2024
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 Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants