Skip to content

sys.exit() is not considered as noreturn #13592

@socketpair

Description

@socketpair

https://mypy-play.net/?mypy=latest&python=3.10&flags=strict%2Cstrict-equality&gist=e86aa52c05acd36b6c04067cb6f44ce1

import sys

def main() -> int:
    return sys.exit(42)

MyPy finds nothing wrong here.

Anyway, this should be valid:

try:
    sys.exit(42)
except SystemExit:
    print('xxx') # this line IS reachable.

i.e. this function either raises specific exception or noreturn.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions