python-3.xlintflake8pyflakes

How to set flake8 to catch a not-callable?


On this test program:

def func():
    foo = (
        (1, 2)
        (3, 4)
    )

Command python -m py_compile my_script.py warns "SyntaxWarning: 'tuple' object is not callable; perhaps you missed a comma?" and pylint --disable=all --enable=E1102 my_script.py outputs "E1102: (1, 2) is not callable (not-callable)".

But flake8 shows no errors or warnings. How can I set it to catch (output or warn) not-callable declaration?

I'm using:

3.7.9 (mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.8.2 on Linux (WSL2)


Solution

  • flake8 out of the box does not have a way to catch that particular SyntaxWarning

    you can however use the standard library directly to catch this:

    $ python3 -Werror -m compileall t.py
    Compiling 't.py'...
    ***   File "t.py", line 3
        (1, 2)
        ^
    SyntaxError: 'tuple' object is not callable; perhaps you missed a comma?
    

    usually you can also turn SyntaxWarnings into SyntaxErrors by raising the warning level, but for whatever reason it doesn't seem to work for this warning (likely because this warning is triggered at compile time instead of parse time):

    $ python3 -Werror -c 'import ast; ast.parse("def f():()()")'
    $
    

    otherwise you would be able to trigger this with PYTHONWARNINGS=error::SyntaxWarning flake8 ... (but sadly, you can't)


    disclaimer: I am the current flake8 maintainer and a pyflakes maintainer (where this would likely get implemented)