Closed ItsDrike closed 2 weeks ago
Pyright is working as intended here, so I don't consider this a bug.
Pyright's reachability analysis honors call expressions where the LHS of the call expression has a declared type. It doesn't honor call expressions where the LHS of the call expression has an inferred type. This is an intentional design decisions that weighs tradeoffs between functionality and performance.
If you want pyright to treat case b
as unreachable, you can do the following:
async def b() -> None:
cr: Callable[[], Coroutine[Any, Any, Never]] = cast(Any, async_normal_func)
await cr()
print("x")
Describe the bug Pyright is generally able to identify unreachable blocks of code, this works for regular functions that have a return type of
NoReturn
orNever
, but also for async functions with this return type. This logic even works with an explicitly set type-hint a variable as a synchronous function, like:Callable[[], Never]
Oddly enough though, it does not work with a type-hint like this for an async function (neither withCoroutine[Any, Any, Never]
norAwaitable[Never]
)Code or Screenshots