Back to Intellij Community

PySuspiciousBooleanConditionInspection

python/python-psi-impl/resources/inspectionDescriptions/PySuspiciousBooleanConditionInspection.html

2025.3-rc-2603 B
Original Source

Reports coroutines used in boolean contexts (if/while/ternary) without being awaited.

Using a coroutine object directly in a boolean condition will always evaluate to True, which is likely not the intended behavior. The coroutine must be awaited to get its actual boolean value.

Example:

async def check() -> bool:
    return True

async def main():
    if check(): # Always True - coroutine object is truthy
        print("hi")

Should be:

async def check() -> bool:
    return True

async def main():
    if await check(): # Correctly awaits the coroutine
        print("hi")