Skip to content

comparison-with-callable false positive then type of variable is a Callable #3987

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

Closed
LefterisJP opened this issue Dec 20, 2020 · 2 comments
Closed
Labels
Checkers Related to a checker 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

@LefterisJP
Copy link
Contributor

LefterisJP commented Dec 20, 2020

Small note: You guys are awesome. Thanks a lot for pylint 🤗

Steps to reproduce

import operator
from typing import Callable


def foo(op: Callable = operator.add) -> None:
    if op == operator.sub:
        print('do something with sub')
    elif op == operator.add:
        print('do something with add')
    else:
        print('no idea')

Current behavior

Getting:

test2.py:6:7: W0143: Comparing against a callable, did you omit the parenthesis? (comparison-with-callable)
test2.py:8:9: W0143: Comparing against a callable, did you omit the parenthesis? (comparison-with-callable)

Expected behavior

I would expect that this error should not be returned since it's obviously an intended comparison with a callable. You want to do something depending on the callable type that op is. So no need for parentheses as suggested by the example here.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.7.9 (default, Sep 26 2020, 15:11:06)
[GCC 10.2.0]

LefterisJP added a commit to LefterisJP/rotkehlchen that referenced this issue Dec 20, 2020
Also ignoring a false positive.
Made an issue for it here: pylint-dev/pylint#3987
@PCManticore PCManticore added Bug 🪲 Checkers Related to a checker labels Dec 26, 2020
@PCManticore
Copy link
Contributor

Thanks for the report, I can confirm this is a bug.

@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 Bug 🪲 labels Jun 30, 2022
@Pierre-Sassoulas Pierre-Sassoulas changed the title comparison-with-callable false positive then type of variable is a Callable comparison-with-callable false positive then type of variable is a Callable Jun 30, 2022
@jacobtylerwalls
Copy link
Member

Can't reproduce on main (8854350)

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checkers Related to a checker 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

4 participants