Skip to content

Commit b26c31a

Browse files
author
Kevin Kirsche
authored
Update sys.exit and SystemExit.code to have the same types (#8554)
1 parent 5435ed7 commit b26c31a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

stdlib/builtins.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ else:
12791279
__locals: Mapping[str, object] | None = ...,
12801280
) -> None: ...
12811281

1282-
def exit(code: object = ...) -> NoReturn: ...
1282+
def exit(code: sys._ExitCode = ...) -> NoReturn: ...
12831283

12841284
class filter(Iterator[_T], Generic[_T]):
12851285
@overload
@@ -1616,7 +1616,7 @@ else:
16161616
@overload
16171617
def pow(__base: _SupportsSomeKindOfPow, __exp: complex, __mod: None = ...) -> complex: ...
16181618

1619-
def quit(code: object = ...) -> NoReturn: ...
1619+
def quit(code: sys._ExitCode = ...) -> NoReturn: ...
16201620

16211621
class reversed(Iterator[_T], Generic[_T]):
16221622
@overload
@@ -1794,7 +1794,7 @@ class GeneratorExit(BaseException): ...
17941794
class KeyboardInterrupt(BaseException): ...
17951795

17961796
class SystemExit(BaseException):
1797-
code: int
1797+
code: sys._ExitCode
17981798

17991799
class Exception(BaseException): ...
18001800

stdlib/sys.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ from typing_extensions import Literal, TypeAlias, final
1111

1212
_T = TypeVar("_T")
1313

14+
# see https://github.com/python/typeshed/issues/8513#issue-1333671093 for the rationale behind this alias
15+
_ExitCode: TypeAlias = str | int | None
1416
_OptExcInfo: TypeAlias = OptExcInfo # noqa: Y047 # TODO: obsolete, remove fall 2022 or later
1517

1618
# Intentionally omits one deprecated and one optional method of `importlib.abc.MetaPathFinder`
@@ -221,8 +223,7 @@ def exc_info() -> OptExcInfo: ...
221223
if sys.version_info >= (3, 11):
222224
def exception() -> BaseException | None: ...
223225

224-
# sys.exit() accepts an optional argument of anything printable
225-
def exit(__status: object = ...) -> NoReturn: ...
226+
def exit(__status: _ExitCode = ...) -> NoReturn: ...
226227
def getallocatedblocks() -> int: ...
227228
def getdefaultencoding() -> str: ...
228229

0 commit comments

Comments
 (0)