-
Notifications
You must be signed in to change notification settings - Fork 135
Closed
astral-sh/ruff
#18333Description
Summary
The following code emits a invalid-return-type diagnostic, but shouldn't:
from typing import NoReturn
import sys
def f() -> NoReturn:
# ^^^^^^^^ Function can implicitly return `None`, which is not assignable to return type `Never`
sys.exit(1)sys.exit is annotated with returning NoReturn, but the problem is that we don't have an explicit return statement here.
This is related to unreachable code analysis. We already have some special handling for detecting whether or not the end of scope is reachable (i.e. replacing sys.exit(1) with while True: pass works fine), but this does not take calls to functions returning Never/NoReturn into account.
AlexWaygood, starsep, konstin, cakemanny, Avasam and 6 more