Skip to content
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

Add truthy-coroutine check #16069

Open
ikonst opened this issue Sep 7, 2023 · 0 comments
Open

Add truthy-coroutine check #16069

ikonst opened this issue Sep 7, 2023 · 0 comments
Labels
feature topic-async async, await, asyncio

Comments

@ikonst
Copy link
Contributor

ikonst commented Sep 7, 2023

Feature

async def func() -> bool:
    return True

async def func2() -> None:
    if func():
        print("hi")

In this code, a likely fix is to change func() to await func(). Meanwhile, it'll always be true since a Coroutine is always true. The truthy-bool check could flag it but it's not enabled by default. We can add a new truthy-coroutine check (like truthy-function) for the specific case of using a Coroutine in boolean context.

The error message can suggest that an await might've been mistakenly omitted.

@ikonst ikonst added the feature label Sep 7, 2023
@AlexWaygood AlexWaygood added the topic-async async, await, asyncio label Sep 9, 2023
erictraut pushed a commit to microsoft/pyright that referenced this issue Sep 9, 2023
…e, which always evaluates to True. This is likely indicative of a missing `await` keyword. This addresses a feature request logged in the mypy issue tracker: python/mypy#16069.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-async async, await, asyncio
Projects
None yet
Development

No branches or pull requests

2 participants