Description
Feature
Extend unused-coroutine
to also encompass directly using the unawaited result with if/while, or perhaps also in other instances where it's used as a condition such as boolean operations etc. Or since the return value technically is used, introduce another error code.
Pitch
Currently no warning is raised for the following code:
async def foo() -> bool:
return False
if foo():
print("foo is true!")
because the return value of the coroutine technically is used. But it's very clearly an error, will give a RuntimeWarning
, and bool(foo())
always evaluates to True
.
I also have a hard time coming up with reasonable scenarios where the above functionality is desired, other than perhaps some weird logic for figuring out if a function is async or not - but in that case the object should be a union of those types and the type checker should be able to handle it.