pylint
pylint copied to clipboard
False Positive W0143-comparison-with-callable when using derived property descriptors
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