pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False positive on W0143, comparing a property to a something that is not a callable

Open tipanverella opened this issue 8 months ago • 1 comments

Bug description

I get the following complaint from pylint:


models.py:172:11: W0143: Comparing against a callable, did you omit the parenthesis? (comparison-with-callable)

The line in question is:

if cls.graph_type == TableGraphType.NODE:


where `graph_type` is defined as follows:

```python
    @classmethod
    @property
    def graph_type(cls) -> Optional[TableGraphType]:
        _gt = None
        if "id" in cls.__fields__:
            _gt = TableGraphType.NODE
        elif len(cls.foreign_keys) == 2:
            _gt = TableGraphType.EDGE
        return _gt


### Configuration

_No response_

### Command used

```shell
poetry run pylint models.py

Pylint output

************* Module models
models.py:172:11: W0143: Comparing against a callable, did you omit the parenthesis? (comparison-with-callable)

Expected behavior

no message as graph_type, being a property, should not require parenthesis!

Pylint version

as reported by poetry:


 name         : pylint                     
 version      : 2.17.5                     
 description  : python code static checker 


### OS / Environment

Darwin c889f3bb632b.ant.amazon.com 22.6.0 Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000 arm64


### Additional dependencies

_No response_

tipanverella avatar Oct 27 '23 17:10 tipanverella

Also seeing this using the meta-class approach to classmethod property which is required for Python >= 3.10 per:

  • https://github.com/python/cpython/issues/89519#issuecomment-1405882053

Repro:

class MetaC(type):
    @property
    def expensive_class_property(cls) -> int:
        return 1


class C(metaclass=MetaC):
    @property
    def expensive_class_property(self) -> int:
        return self.__class__.expensive_class_property


if C.expensive_class_property == 1:  # PylintW0143:comparison-with-callable
    print('ok')

c = C()

if c.expensive_class_property == 1:  # PylintW0143:comparison-with-callable
    print('ok')

davetapley avatar Apr 18 '24 01:04 davetapley