Skip to content

calls to functions returning Never/NoReturn are terminal #180

@sharkdp

Description

@sharkdp

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions