Skip to content

unused-courotine should trigger when using a coroutine call as a condition without awaiting it #16921

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

Open
jakkdl opened this issue Feb 16, 2024 · 0 comments
Labels

Comments

@jakkdl
Copy link

jakkdl commented Feb 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant