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 on W0143, comparing a property to a something that is not a callable #9194

Open
tipanverella opened this issue Oct 27, 2023 · 1 comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling

Comments

@tipanverella
Copy link

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 tipanverella added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 27, 2023
@davetapley
Copy link

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

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling
Projects
None yet
Development

No branches or pull requests

2 participants