Skip to content

stdlib: Use Never instead of NoReturn #13893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions stdlib/_sitebuiltins.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import sys
from collections.abc import Iterable
from typing import ClassVar, Literal, NoReturn
from typing import ClassVar, Literal
from typing_extensions import Never

class Quitter:
name: str
eof: str
def __init__(self, name: str, eof: str) -> None: ...
def __call__(self, code: sys._ExitCode = None) -> NoReturn: ...
def __call__(self, code: sys._ExitCode = None) -> Never: ...

class _Printer:
MAXLINES: ClassVar[Literal[23]]
Expand Down
8 changes: 4 additions & 4 deletions stdlib/_thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ from _typeshed import structseq
from collections.abc import Callable
from threading import Thread
from types import TracebackType
from typing import Any, Final, NoReturn, final, overload
from typing_extensions import TypeVarTuple, Unpack
from typing import Any, Final, final, overload
from typing_extensions import Never, TypeVarTuple, Unpack

_Ts = TypeVarTuple("_Ts")

Expand Down Expand Up @@ -76,8 +76,8 @@ if sys.version_info >= (3, 10):
else:
def interrupt_main() -> None: ...

def exit() -> NoReturn: ...
def exit_thread() -> NoReturn: ... # Obsolete synonym for exit()
def exit() -> Never: ...
def exit_thread() -> Never: ... # Obsolete synonym for exit()
def allocate_lock() -> LockType: ...
def allocate() -> LockType: ... # Obsolete synonym for allocate_lock()
def get_ident() -> int: ...
Expand Down
5 changes: 3 additions & 2 deletions stdlib/_winapi.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys
from _typeshed import ReadableBuffer
from collections.abc import Sequence
from typing import Any, Final, Literal, NoReturn, final, overload
from typing import Any, Final, Literal, final, overload
from typing_extensions import Never

if sys.platform == "win32":
ABOVE_NORMAL_PRIORITY_CLASS: Final = 0x8000
Expand Down Expand Up @@ -223,7 +224,7 @@ if sys.platform == "win32":
options: int = 0,
/,
) -> int: ...
def ExitProcess(ExitCode: int, /) -> NoReturn: ...
def ExitProcess(ExitCode: int, /) -> Never: ...
def GetACP() -> int: ...
def GetFileType(handle: int) -> int: ...
def GetCurrentProcess() -> int: ...
Expand Down
10 changes: 5 additions & 5 deletions stdlib/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import sys
from _typeshed import SupportsWrite, sentinel
from collections.abc import Callable, Generator, Iterable, Sequence
from re import Pattern
from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload
from typing_extensions import Self, TypeAlias, deprecated
from typing import IO, Any, ClassVar, Final, Generic, Protocol, TypeVar, overload
from typing_extensions import Never, Self, TypeAlias, deprecated

__all__ = [
"ArgumentParser",
Expand Down Expand Up @@ -109,7 +109,7 @@ class _ActionsContainer:
def _pop_action_class(self, kwargs: Any, default: type[Action] | None = None) -> type[Action]: ...
def _get_handler(self) -> Callable[[Action, Iterable[tuple[str, Action]]], Any]: ...
def _check_conflict(self, action: Action) -> None: ...
def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> NoReturn: ...
def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> Never: ...
def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> None: ...

class _FormatterClass(Protocol):
Expand Down Expand Up @@ -192,8 +192,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
@overload
def parse_known_args(self, *, namespace: _N) -> tuple[_N, list[str]]: ...
def convert_arg_line_to_args(self, arg_line: str) -> list[str]: ...
def exit(self, status: int = 0, message: str | None = None) -> NoReturn: ...
def error(self, message: str) -> NoReturn: ...
def exit(self, status: int = 0, message: str | None = None) -> Never: ...
def error(self, message: str) -> Never: ...
@overload
def parse_intermixed_args(self, args: Sequence[str] | None = None, namespace: None = None) -> Namespace: ...
@overload
Expand Down
14 changes: 7 additions & 7 deletions stdlib/asyncio/trsock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ from _typeshed import ReadableBuffer
from builtins import type as Type # alias to avoid name clashes with property named "type"
from collections.abc import Iterable
from types import TracebackType
from typing import Any, BinaryIO, NoReturn, overload
from typing_extensions import TypeAlias
from typing import Any, BinaryIO, overload
from typing_extensions import Never, TypeAlias

# These are based in socket, maybe move them out into _typeshed.pyi or such
_Address: TypeAlias = socket._Address
Expand All @@ -21,7 +21,7 @@ class TransportSocket:
def type(self) -> int: ...
@property
def proto(self) -> int: ...
def __getstate__(self) -> NoReturn: ...
def __getstate__(self) -> Never: ...
def fileno(self) -> int: ...
def dup(self) -> socket.socket: ...
def get_inheritable(self) -> bool: ...
Expand All @@ -36,7 +36,7 @@ class TransportSocket:
def setsockopt(self, level: int, optname: int, value: None, optlen: int) -> None: ...
def getpeername(self) -> _RetAddress: ...
def getsockname(self) -> _RetAddress: ...
def getsockbyname(self) -> NoReturn: ... # This method doesn't exist on socket, yet is passed through?
def getsockbyname(self) -> Never: ... # This method doesn't exist on socket, yet is passed through?
def settimeout(self, value: float | None) -> None: ...
def gettimeout(self) -> float | None: ...
def setblocking(self, flag: bool) -> None: ...
Expand All @@ -49,7 +49,7 @@ class TransportSocket:
if sys.platform == "win32":
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> None: ...
else:
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> NoReturn: ...
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> Never: ...

def listen(self, backlog: int = ..., /) -> None: ...
def makefile(self) -> BinaryIO: ...
Expand All @@ -63,7 +63,7 @@ class TransportSocket:
else:
def sendmsg_afalg(
self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ...
) -> NoReturn: ...
) -> Never: ...

def sendmsg(
self, buffers: Iterable[ReadableBuffer], ancdata: Iterable[_CMSG] = ..., flags: int = ..., address: _Address = ..., /
Expand All @@ -78,7 +78,7 @@ class TransportSocket:
if sys.platform == "win32":
def share(self, process_id: int) -> bytes: ...
else:
def share(self, process_id: int) -> NoReturn: ...
def share(self, process_id: int) -> Never: ...

def recv_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> int: ...
def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> tuple[int, _RetAddress]: ...
Expand Down
11 changes: 6 additions & 5 deletions stdlib/asyncio/windows_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import socket
import sys
from _typeshed import Incomplete, ReadableBuffer, WriteableBuffer
from collections.abc import Callable
from typing import IO, Any, ClassVar, Final, NoReturn
from typing import IO, Any, ClassVar, Final
from typing_extensions import Never

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

Expand Down Expand Up @@ -88,13 +89,13 @@ if sys.platform == "win32":
class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
_loop_factory: ClassVar[type[SelectorEventLoop]]
if sys.version_info < (3, 14):
def get_child_watcher(self) -> NoReturn: ...
def set_child_watcher(self, watcher: Any) -> NoReturn: ...
def get_child_watcher(self) -> Never: ...
def set_child_watcher(self, watcher: Any) -> Never: ...

class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
_loop_factory: ClassVar[type[ProactorEventLoop]]
def get_child_watcher(self) -> NoReturn: ...
def set_child_watcher(self, watcher: Any) -> NoReturn: ...
def get_child_watcher(self) -> Never: ...
def set_child_watcher(self, watcher: Any) -> Never: ...

DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy
if sys.version_info >= (3, 13):
Expand Down
6 changes: 3 additions & 3 deletions stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import sys
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
from types import GenericAlias
from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, final, overload
from typing_extensions import Self
from typing import Any, ClassVar, Generic, SupportsIndex, TypeVar, final, overload
from typing_extensions import Never, Self

if sys.version_info >= (3, 10):
from collections.abc import (
Expand Down Expand Up @@ -281,7 +281,7 @@ class Counter(dict[_T, int], Generic[_T]):
def elements(self) -> Iterator[_T]: ...
def most_common(self, n: int | None = None) -> list[tuple[_T, int]]: ...
@classmethod
def fromkeys(cls, iterable: Any, v: int | None = None) -> NoReturn: ... # type: ignore[override]
def fromkeys(cls, iterable: Any, v: int | None = None) -> Never: ... # type: ignore[override]
@overload
def subtract(self, iterable: None = None, /) -> None: ...
@overload
Expand Down
6 changes: 3 additions & 3 deletions stdlib/datetime.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
from abc import abstractmethod
from time import struct_time
from typing import ClassVar, Final, NoReturn, SupportsIndex, final, overload, type_check_only
from typing_extensions import CapsuleType, Self, TypeAlias, deprecated
from typing import ClassVar, Final, SupportsIndex, final, overload, type_check_only
from typing_extensions import CapsuleType, Never, Self, TypeAlias, deprecated

if sys.version_info >= (3, 11):
__all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC")
Expand Down Expand Up @@ -97,7 +97,7 @@ class date:
def __add__(self, value: timedelta, /) -> Self: ...
def __radd__(self, value: timedelta, /) -> Self: ...
@overload
def __sub__(self, value: datetime, /) -> NoReturn: ...
def __sub__(self, value: datetime, /) -> Never: ...
@overload
def __sub__(self, value: Self, /) -> timedelta: ...
@overload
Expand Down
8 changes: 4 additions & 4 deletions stdlib/importlib/readers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import zipfile
from _typeshed import StrPath
from collections.abc import Iterable, Iterator
from io import BufferedReader
from typing import Literal, NoReturn, TypeVar
from typing import Literal, TypeVar
from typing_extensions import Never

if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -46,8 +46,8 @@ if sys.version_info >= (3, 10):
class MultiplexedPath(abc.Traversable):
def __init__(self, *paths: abc.Traversable) -> None: ...
def iterdir(self) -> Iterator[abc.Traversable]: ...
def read_bytes(self) -> NoReturn: ...
def read_text(self, *args: Never, **kwargs: Never) -> NoReturn: ... # type: ignore[override]
def read_bytes(self) -> Never: ...
def read_text(self, *args: Never, **kwargs: Never) -> Never: ... # type: ignore[override]
def is_dir(self) -> Literal[True]: ...
def is_file(self) -> Literal[False]: ...

Expand All @@ -61,7 +61,7 @@ if sys.version_info >= (3, 10):
if sys.version_info < (3, 12):
__truediv__ = joinpath

def open(self, *args: Never, **kwargs: Never) -> NoReturn: ... # type: ignore[override]
def open(self, *args: Never, **kwargs: Never) -> Never: ... # type: ignore[override]
@property
def name(self) -> str: ...

Expand Down
6 changes: 3 additions & 3 deletions stdlib/importlib/resources/simple.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import abc
import sys
from collections.abc import Iterator
from io import TextIOWrapper
from typing import IO, Any, BinaryIO, Literal, NoReturn, overload
from typing import IO, Any, BinaryIO, Literal, overload
from typing_extensions import Never

if sys.version_info >= (3, 11):
Expand Down Expand Up @@ -40,15 +40,15 @@ if sys.version_info >= (3, 11):
def open(self, mode: Literal["rb"]) -> BinaryIO: ...
@overload
def open(self, mode: str) -> IO[Any]: ...
def joinpath(self, name: Never) -> NoReturn: ... # type: ignore[override]
def joinpath(self, name: Never) -> Never: ... # type: ignore[override]

class ResourceContainer(Traversable, metaclass=abc.ABCMeta):
reader: SimpleReader
def __init__(self, reader: SimpleReader) -> None: ...
def is_dir(self) -> Literal[True]: ...
def is_file(self) -> Literal[False]: ...
def iterdir(self) -> Iterator[ResourceHandle | ResourceContainer]: ...
def open(self, *args: Never, **kwargs: Never) -> NoReturn: ... # type: ignore[override]
def open(self, *args: Never, **kwargs: Never) -> Never: ... # type: ignore[override]
if sys.version_info < (3, 12):
def joinpath(self, *descendants: str) -> Traversable: ...

Expand Down
7 changes: 4 additions & 3 deletions stdlib/lib2to3/pgen2/pgen.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from _typeshed import Incomplete, StrPath
from collections.abc import Iterable, Iterator
from typing import IO, ClassVar, NoReturn, overload
from typing import IO, ClassVar, overload
from typing_extensions import Never

from . import grammar
from .tokenize import _TokenInfo
Expand Down Expand Up @@ -30,9 +31,9 @@ class ParserGenerator:
def expect(self, type: int, value: str | None = None) -> str: ...
def gettoken(self) -> None: ...
@overload
def raise_error(self, msg: object) -> NoReturn: ...
def raise_error(self, msg: object) -> Never: ...
@overload
def raise_error(self, msg: str, *args: object) -> NoReturn: ...
def raise_error(self, msg: str, *args: object) -> Never: ...

class NFAState:
arcs: list[tuple[str | None, NFAState]]
Expand Down
5 changes: 3 additions & 2 deletions stdlib/lib2to3/refactor.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ from collections.abc import Container, Generator, Iterable, Mapping
from logging import Logger, _ExcInfoType
from multiprocessing import JoinableQueue
from multiprocessing.synchronize import Lock
from typing import Any, ClassVar, Final, NoReturn, overload
from typing import Any, ClassVar, Final, overload
from typing_extensions import Never

from .btm_matcher import BottomMatcher
from .fixer_base import BaseFix
Expand Down Expand Up @@ -39,7 +40,7 @@ class RefactoringTool:
self, fixer_names: Iterable[str], options: Mapping[str, object] | None = None, explicit: Container[str] | None = None
) -> None: ...
def get_fixers(self) -> tuple[list[BaseFix], list[BaseFix]]: ...
def log_error(self, msg: str, *args: Iterable[str], **kwargs: _ExcInfoType) -> NoReturn: ...
def log_error(self, msg: str, *args: Iterable[str], **kwargs: _ExcInfoType) -> Never: ...
@overload
def log_message(self, msg: object) -> None: ...
@overload
Expand Down
6 changes: 3 additions & 3 deletions stdlib/mmap.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
from _typeshed import ReadableBuffer, Unused
from collections.abc import Iterator
from typing import Final, Literal, NoReturn, overload
from typing_extensions import Self
from typing import Final, Literal, overload
from typing_extensions import Never, Self

ACCESS_DEFAULT: int
ACCESS_READ: int
Expand Down Expand Up @@ -74,7 +74,7 @@ class mmap:
def __getitem__(self, key: int, /) -> int: ...
@overload
def __getitem__(self, key: slice, /) -> bytes: ...
def __delitem__(self, key: int | slice, /) -> NoReturn: ...
def __delitem__(self, key: int | slice, /) -> Never: ...
@overload
def __setitem__(self, key: int, value: int, /) -> None: ...
@overload
Expand Down
8 changes: 4 additions & 4 deletions stdlib/optparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import builtins
from _typeshed import MaybeNone, SupportsWrite
from abc import abstractmethod
from collections.abc import Callable, Iterable, Mapping, Sequence
from typing import Any, ClassVar, Final, Literal, NoReturn, overload
from typing_extensions import Self
from typing import Any, ClassVar, Final, Literal, overload
from typing_extensions import Never, Self

__all__ = [
"Option",
Expand Down Expand Up @@ -288,8 +288,8 @@ class OptionParser(OptionContainer):
def check_values(self, values: Values, args: list[str]) -> tuple[Values, list[str]]: ...
def disable_interspersed_args(self) -> None: ...
def enable_interspersed_args(self) -> None: ...
def error(self, msg: str) -> NoReturn: ...
def exit(self, status: int = 0, msg: str | None = None) -> NoReturn: ...
def error(self, msg: str) -> Never: ...
def exit(self, status: int = 0, msg: str | None = None) -> Never: ...
def expand_prog_name(self, s: str) -> str: ...
def format_epilog(self, formatter: HelpFormatter) -> str: ...
def format_help(self, formatter: HelpFormatter | None = None) -> str: ...
Expand Down
Loading