Skip to content

Commit 97e83f6

Browse files
authored
Replace NoReturn with Never (#16079)
1 parent e16e908 commit 97e83f6

126 files changed

Lines changed: 438 additions & 398 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

stdlib/@tests/test_cases/builtins/check_pow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# that passing 0 for the third argument will lead to an exception being raised
1616
# (see discussion in #8566)
1717
#
18-
# assert_type(pow(2, 4, 0), NoReturn)
18+
# assert_type(pow(2, 4, 0), Never)
1919

2020
assert_type(pow(2, 4), int)
2121
# pyright infers a literal type here, but mypy does not.

stdlib/_sitebuiltins.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import sys
22
from collections.abc import Iterable
3-
from typing import ClassVar, Literal, NoReturn
3+
from typing import ClassVar, Literal
4+
from typing_extensions import Never
45

56
class Quitter:
67
name: str
78
eof: str
89
def __init__(self, name: str, eof: str) -> None: ...
9-
def __call__(self, code: sys._ExitCode = None) -> NoReturn: ...
10+
def __call__(self, code: sys._ExitCode = None) -> Never: ...
1011

1112
class _Printer:
1213
MAXLINES: ClassVar[Literal[23]]

stdlib/_thread.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ from _typeshed import structseq
44
from collections.abc import Callable
55
from threading import Thread
66
from types import TracebackType
7-
from typing import Any, Final, NoReturn, final, overload
8-
from typing_extensions import TypeVarTuple, Unpack, deprecated, disjoint_base
7+
from typing import Any, Final, final, overload
8+
from typing_extensions import Never, TypeVarTuple, Unpack, deprecated, disjoint_base
99

1010
_Ts = TypeVarTuple("_Ts")
1111

@@ -82,9 +82,9 @@ def start_new(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]
8282
def start_new(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ... # undocumented
8383

8484
def interrupt_main(signum: signal.Signals = signal.SIGINT, /) -> None: ...
85-
def exit() -> NoReturn: ...
85+
def exit() -> Never: ...
8686
@deprecated("Obsolete synonym. Use `exit()` instead.")
87-
def exit_thread() -> NoReturn: ... # undocumented
87+
def exit_thread() -> Never: ... # undocumented
8888
def allocate_lock() -> LockType: ...
8989
@deprecated("Obsolete synonym. Use `allocate_lock()` instead.")
9090
def allocate() -> LockType: ... # undocumented

stdlib/_winapi.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sys
22
from _typeshed import ReadableBuffer
33
from collections.abc import Sequence
4-
from typing import Any, Final, Literal, NoReturn, final, overload
4+
from typing import Any, Final, Literal, final, overload
5+
from typing_extensions import Never
56

67
if sys.platform == "win32":
78
ABOVE_NORMAL_PRIORITY_CLASS: Final = 0x8000
@@ -238,7 +239,7 @@ if sys.platform == "win32":
238239
options: int = 0,
239240
/,
240241
) -> int: ...
241-
def ExitProcess(ExitCode: int, /) -> NoReturn: ...
242+
def ExitProcess(ExitCode: int, /) -> Never: ...
242243
def GetACP() -> int: ...
243244
if sys.version_info >= (3, 15):
244245
def DeregisterEventSource(handle: int, /) -> None: ...

stdlib/argparse.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import sys
22
from _typeshed import SupportsWrite, sentinel
33
from collections.abc import Callable, Generator, Iterable, Sequence
44
from re import Pattern
5-
from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only
6-
from typing_extensions import Self, deprecated
5+
from typing import IO, Any, ClassVar, Final, Generic, Protocol, TypeAlias, TypeVar, overload, type_check_only
6+
from typing_extensions import Never, Self, deprecated
77

88
__all__ = [
99
"ArgumentParser",
@@ -123,7 +123,7 @@ class _ActionsContainer:
123123
def _pop_action_class(self, kwargs: Any, default: type[Action] | None = None) -> type[Action]: ...
124124
def _get_handler(self) -> Callable[[Action, Iterable[tuple[str, Action]]], Any]: ...
125125
def _check_conflict(self, action: Action) -> None: ...
126-
def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> NoReturn: ...
126+
def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> Never: ...
127127
def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> None: ...
128128

129129
@type_check_only
@@ -264,8 +264,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
264264
def parse_known_args(self, *, namespace: _N) -> tuple[_N, list[str]]: ...
265265

266266
def convert_arg_line_to_args(self, arg_line: str) -> list[str]: ...
267-
def exit(self, status: int = 0, message: str | None = None) -> NoReturn: ...
268-
def error(self, message: str) -> NoReturn: ...
267+
def exit(self, status: int = 0, message: str | None = None) -> Never: ...
268+
def error(self, message: str) -> Never: ...
269269

270270
@overload
271271
def parse_intermixed_args(self, args: Iterable[str] | None = None, namespace: None = None) -> Namespace: ...

stdlib/asyncio/trsock.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ from _typeshed import ReadableBuffer
44
from builtins import type as Type # alias to avoid name clashes with property named "type"
55
from collections.abc import Iterable
66
from types import TracebackType
7-
from typing import Any, BinaryIO, NoReturn, TypeAlias, overload
8-
from typing_extensions import deprecated
7+
from typing import Any, BinaryIO, TypeAlias, overload
8+
from typing_extensions import Never, deprecated
99

1010
# These are based in socket, maybe move them out into _typeshed.pyi or such
1111
_Address: TypeAlias = socket._Address
@@ -22,7 +22,7 @@ class TransportSocket:
2222
def type(self) -> int: ...
2323
@property
2424
def proto(self) -> int: ...
25-
def __getstate__(self) -> NoReturn: ...
25+
def __getstate__(self) -> Never: ...
2626
def fileno(self) -> int: ...
2727
def dup(self) -> socket.socket: ...
2828
def get_inheritable(self) -> bool: ...
@@ -40,7 +40,7 @@ class TransportSocket:
4040

4141
def getpeername(self) -> _RetAddress: ...
4242
def getsockname(self) -> _RetAddress: ...
43-
def getsockbyname(self) -> NoReturn: ... # This method doesn't exist on socket, yet is passed through?
43+
def getsockbyname(self) -> Never: ... # This method doesn't exist on socket, yet is passed through?
4444
def settimeout(self, value: float | None) -> None: ...
4545
def gettimeout(self) -> float | None: ...
4646
def setblocking(self, flag: bool) -> None: ...
@@ -60,7 +60,7 @@ class TransportSocket:
6060
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> None: ...
6161
else:
6262
@deprecated("Removed in Python 3.11")
63-
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> NoReturn: ...
63+
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> Never: ...
6464

6565
@deprecated("Removed in Python 3.11")
6666
def listen(self, backlog: int = ..., /) -> None: ...
@@ -82,7 +82,7 @@ class TransportSocket:
8282
@deprecated("Removed in Python 3.11.")
8383
def sendmsg_afalg(
8484
self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = 0
85-
) -> NoReturn: ...
85+
) -> Never: ...
8686

8787
@deprecated("Removed in Python 3.11.")
8888
def sendmsg(
@@ -113,7 +113,7 @@ class TransportSocket:
113113
def share(self, process_id: int) -> bytes: ...
114114
else:
115115
@deprecated("Removed in Python 3.11.")
116-
def share(self, process_id: int) -> NoReturn: ...
116+
def share(self, process_id: int) -> Never: ...
117117

118118
@deprecated("Removed in Python 3.11.")
119119
def recv_into(self, buffer: _WriteBuffer, nbytes: int = 0, flags: int = 0) -> int: ...

stdlib/asyncio/windows_events.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import socket
22
import sys
33
from _typeshed import Incomplete, ReadableBuffer, WriteableBuffer
44
from collections.abc import Callable
5-
from typing import IO, Any, ClassVar, Final, NoReturn
5+
from typing import IO, Any, ClassVar, Final
6+
from typing_extensions import Never
67

78
from . import events, futures, proactor_events, selector_events, streams, windows_utils
89

@@ -105,13 +106,13 @@ if sys.platform == "win32":
105106
else:
106107
class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
107108
_loop_factory: ClassVar[type[SelectorEventLoop]]
108-
def get_child_watcher(self) -> NoReturn: ...
109-
def set_child_watcher(self, watcher: Any) -> NoReturn: ...
109+
def get_child_watcher(self) -> Never: ...
110+
def set_child_watcher(self, watcher: Any) -> Never: ...
110111

111112
class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
112113
_loop_factory: ClassVar[type[ProactorEventLoop]]
113-
def get_child_watcher(self) -> NoReturn: ...
114-
def set_child_watcher(self, watcher: Any) -> NoReturn: ...
114+
def get_child_watcher(self) -> Never: ...
115+
def set_child_watcher(self, watcher: Any) -> Never: ...
115116

116117
if sys.version_info >= (3, 14):
117118
_DefaultEventLoopPolicy = _WindowsProactorEventLoopPolicy

stdlib/builtins.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ _SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs a
21122112
)
21132113

21142114
# TODO: `pow(int, int, Literal[0])` fails at runtime,
2115-
# but adding a `NoReturn` overload isn't a good solution for expressing that (see #8566).
2115+
# but adding a `Never` overload isn't a good solution for expressing that (see #8566).
21162116
@overload
21172117
def pow(base: int, exp: int, mod: int) -> int: ...
21182118
@overload

stdlib/collections/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ from collections.abc import (
1414
ValuesView,
1515
)
1616
from types import GenericAlias
17-
from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, final, overload, type_check_only
18-
from typing_extensions import Self, disjoint_base
17+
from typing import Any, ClassVar, Generic, SupportsIndex, TypeVar, final, overload, type_check_only
18+
from typing_extensions import Never, Self, disjoint_base
1919

2020
if sys.version_info >= (3, 15):
2121
from builtins import frozendict
@@ -300,7 +300,7 @@ class Counter(dict[_T, int], Generic[_T]):
300300
def elements(self) -> Iterator[_T]: ...
301301
def most_common(self, n: int | None = None) -> list[tuple[_T, int]]: ...
302302
@classmethod
303-
def fromkeys(cls, iterable: Any, v: int | None = None) -> NoReturn: ... # type: ignore[override]
303+
def fromkeys(cls, iterable: Any, v: int | None = None) -> Never: ... # type: ignore[override]
304304

305305
@overload
306306
def subtract(self, iterable: None = None, /) -> None: ...

stdlib/datetime.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import sys
22
from abc import abstractmethod
33
from time import struct_time
4-
from typing import ClassVar, Final, NoReturn, SupportsIndex, TypeAlias, final, overload, type_check_only
5-
from typing_extensions import CapsuleType, Self, deprecated, disjoint_base
4+
from typing import ClassVar, Final, SupportsIndex, TypeAlias, final, overload, type_check_only
5+
from typing_extensions import CapsuleType, Never, Self, deprecated, disjoint_base
66

77
if sys.version_info >= (3, 11):
88
__all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC")
@@ -114,7 +114,7 @@ class date:
114114
def __radd__(self, value: timedelta, /) -> Self: ...
115115

116116
@overload
117-
def __sub__(self, value: datetime, /) -> NoReturn: ...
117+
def __sub__(self, value: datetime, /) -> Never: ...
118118
@overload
119119
def __sub__(self, value: Self, /) -> timedelta: ...
120120
@overload

0 commit comments

Comments
 (0)