Open
Description
Consider this example:
def f(x: int) -> str: pass
if f:
pass
It generates this error:
t.py:3: error: Function "Callable[[int], str]" could always be true in boolean context [truthy-function]
Instead, if we have a direct reference to a function definition, we could generate a message like this which would be clearer, especially if the signature is complex:
t.py:3: error: Function "f" could always be true in boolean context [truthy-function]
There are at least these different cases to consider:
- Direct reference to a function using a short name of a function (similar to the above example).
- Direct reference to a function using a module prefix (e.g.
if mod.func:
). - Reference to a method (e.g.
if obj.method:
). - Reference to a variable/attribute (
Var
node) with typeCallable[...]
(in this case we could show the name of the variable/attribute or the callable type -- both would be okay). - Any other expression that produces a callable value, such as
if func():
wherefunc
returns a callable. Here the best option is to show the callable type as we do now.