Skip to content

sys.exit(object) is not accepted #14821

@patrickdepinguin

Description

@patrickdepinguin

The Python documentation says:

https://docs.python.org/3/library/sys.html#sys.exit

sys.exit([arg])

    [...]

    The optional argument arg can be an integer giving the exit status (defaulting to zero), 
    or another type of object. [...] If another type of object is passed, None is equivalent to
    passing zero, and any other object is printed to stderr and results in an exit code of 1.

For example:

import sys
sys.exit(RuntimeError('oops'))

(which more commonly would be try...except RuntimeError as exc: [...]; sys.exit(exc) )

Output for mypy 1.18.2:

/tmp/test.py:3: error: Argument 1 to "exit" has incompatible type "RuntimeError"; expected "str | int | None"  [arg-type]

mypy only accepts str | int | None, as a result of issue #8513.

But, since this is valid Python code, I feel that mypy should accept it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions