pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Doc why `is` is superior to `==` in `comparison-with-callable` when comparing two callables

Open sam-s opened this issue 3 years ago • 9 comments

Bug description

W0143(comparison-with-callable) is issued for no good reason, when both parts are callable:

"""test
"""
def f0(x):
    "identity"
    return x
def f1(x):
    "add 1"
    return x+1

def main(f, x):
    "test function"
    if f == f0:
        print("identity")
    else:
        print(f.__name__)
    return f(x)

here the clear intent is to compare callables, so the warning appears to be unnecessary. While I can disable it, it seems that it should not be issued when both parts of the comparison are callable.

Configuration

none

Command used

pylint a.py

Pylint output

a.py:12: [W0143(comparison-with-callable), main] Comparing against a callable, did you omit the parenthesis?

Expected behavior

no diagnostics

Pylint version

pylint 2.15.5
astroid 2.12.12
Python 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0]

OS / Environment

popos 22.04

Additional dependencies

No response

sam-s avatar Nov 07 '22 01:11 sam-s