From de26a3d109dad3cd6103bf782b7a6b6bb947ddca Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 13 Oct 2019 21:51:43 +0200 Subject: [PATCH] Remove raise statements from function bodies (#3355) While it may eventually be useful to mark the exceptions that can be raised from a function or method, the semantics are currently undefined and unclear. --- stdlib/2/_collections.pyi | 12 ++--- stdlib/2/_hotshot.pyi | 20 ++------ stdlib/2/_socket.pyi | 10 ++-- stdlib/2/_sre.pyi | 22 ++++---- stdlib/2/heapq.pyi | 6 +-- stdlib/2/posix.pyi | 15 ++---- stdlib/2/signal.pyi | 9 ++-- stdlib/2/string.pyi | 5 +- stdlib/2/strop.pyi | 83 ++++++++----------------------- stdlib/2/sys.pyi | 6 +-- stdlib/2/thread.pyi | 6 +-- stdlib/2and3/_heapq.pyi | 6 +-- stdlib/3/_tracemalloc.pyi | 14 +----- stdlib/3/collections/__init__.pyi | 9 ++-- stdlib/3/signal.pyi | 45 ++++------------- stdlib/3/string.pyi | 5 +- stdlib/3/sys.pyi | 3 +- 17 files changed, 77 insertions(+), 199 deletions(-) diff --git a/stdlib/2/_collections.pyi b/stdlib/2/_collections.pyi index 9736a49b9..bee5d67b0 100644 --- a/stdlib/2/_collections.pyi +++ b/stdlib/2/_collections.pyi @@ -23,18 +23,14 @@ class deque(Generic[_T]): def count(self, x: Any) -> int: ... def extend(self, iterable: Iterator[_T]) -> None: ... def extendleft(self, iterable: Iterator[_T]) -> None: ... - def pop(self) -> _T: - raise IndexError() - def popleft(self) -> _T: - raise IndexError() - def remove(self, value: _T) -> None: - raise IndexError() + def pop(self) -> _T: ... + def popleft(self) -> _T: ... + def remove(self, value: _T) -> None: ... def reverse(self) -> None: ... def rotate(self, n: int = ...) -> None: ... def __contains__(self, o: Any) -> bool: ... def __copy__(self) -> deque[_T]: ... - def __getitem__(self, i: int) -> _T: - raise IndexError() + def __getitem__(self, i: int) -> _T: ... def __iadd__(self, other: deque[_T2]) -> deque[Union[_T, _T2]]: ... def __iter__(self) -> Iterator[_T]: ... def __len__(self) -> int: ... diff --git a/stdlib/2/_hotshot.pyi b/stdlib/2/_hotshot.pyi index f75acf243..a4404b0c7 100644 --- a/stdlib/2/_hotshot.pyi +++ b/stdlib/2/_hotshot.pyi @@ -6,29 +6,19 @@ from typing import Any, List, Tuple, Dict, Generic def coverage(a: str) -> Any: ... - -def logreader(a: str) -> LogReaderType: - raise IOError() - raise RuntimeError() - -def profiler(a: str, *args, **kwargs) -> Any: - raise IOError() - +def logreader(a: str) -> LogReaderType: ... +def profiler(a: str, *args, **kwargs) -> Any: ... def resolution() -> Tuple[Any, ...]: ... - class LogReaderType(object): def close(self) -> None: ... - def fileno(self) -> int: - raise ValueError() + def fileno(self) -> int: ... class ProfilerType(object): def addinfo(self, a: str, b: str) -> None: ... def close(self) -> None: ... - def fileno(self) -> int: - raise ValueError() + def fileno(self) -> int: ... def runcall(self, *args, **kwargs) -> Any: ... - def runcode(self, a, b, *args, **kwargs) -> Any: - raise TypeError() + def runcode(self, a, b, *args, **kwargs) -> Any: ... def start(self) -> None: ... def stop(self) -> None: ... diff --git a/stdlib/2/_socket.pyi b/stdlib/2/_socket.pyi index 31ba7638a..f6a058aca 100644 --- a/stdlib/2/_socket.pyi +++ b/stdlib/2/_socket.pyi @@ -256,9 +256,7 @@ class SocketType(object): def accept(self) -> Tuple[SocketType, Tuple[Any, ...]]: ... def bind(self, address: Tuple[Any, ...]) -> None: ... def close(self) -> None: ... - def connect(self, address: Tuple[Any, ...]) -> None: - raise gaierror - raise timeout + def connect(self, address: Tuple[Any, ...]) -> None: ... def connect_ex(self, address: Tuple[Any, ...]) -> int: ... def dup(self) -> SocketType: ... def fileno(self) -> int: ... @@ -266,13 +264,11 @@ class SocketType(object): def getsockname(self) -> Tuple[Any, ...]: ... def getsockopt(self, level: int, option: int, buffersize: int = ...) -> str: ... def gettimeout(self) -> float: ... - def listen(self, backlog: int) -> None: - raise error + def listen(self, backlog: int) -> None: ... def makefile(self, mode: str = ..., buffersize: int = ...) -> IO[Any]: ... def recv(self, buffersize: int, flags: int = ...) -> str: ... def recv_into(self, buffer: bytearray, nbytes: int = ..., flags: int = ...) -> int: ... - def recvfrom(self, buffersize: int, flags: int = ...) -> Tuple[Any, ...]: - raise error + def recvfrom(self, buffersize: int, flags: int = ...) -> Tuple[Any, ...]: ... def recvfrom_into(self, buffer: bytearray, nbytes: int = ..., flags: int = ...) -> int: ... def send(self, data: str, flags: int = ...) -> int: ... diff --git a/stdlib/2/_sre.pyi b/stdlib/2/_sre.pyi index 5ab7ed124..93300f0f2 100644 --- a/stdlib/2/_sre.pyi +++ b/stdlib/2/_sre.pyi @@ -8,10 +8,8 @@ MAXREPEAT: long copyright: str class SRE_Match(object): - def start(self, group: int = ...) -> int: - raise IndexError() - def end(self, group: int = ...) -> int: - raise IndexError() + def start(self, group: int = ...) -> int: ... + def end(self, group: int = ...) -> int: ... def expand(self, s: str) -> Any: ... @overload def group(self) -> str: ... @@ -19,8 +17,7 @@ class SRE_Match(object): def group(self, group: int = ...) -> Optional[str]: ... def groupdict(self) -> Dict[int, Optional[str]]: ... def groups(self) -> Tuple[Optional[str], ...]: ... - def span(self) -> Tuple[int, int]: - raise IndexError() + def span(self) -> Tuple[int, int]: ... @property def regs(self) -> Tuple[Tuple[int, int], ...]: ... # undocumented @@ -44,11 +41,14 @@ class SRE_Pattern(object): def sub(self, repl: str, string: str, count: int = ...) -> Tuple[Any, ...]: ... def subn(self, repl: str, string: str, count: int = ...) -> Tuple[Any, ...]: ... -def compile(pattern: str, flags: int, code: List[int], - groups: int = ..., - groupindex: Mapping[str, int] = ..., - indexgroup: Sequence[int] = ...) -> SRE_Pattern: - raise OverflowError() +def compile( + pattern: str, + flags: int, + code: List[int], + groups: int = ..., + groupindex: Mapping[str, int] = ..., + indexgroup: Sequence[int] = ..., +) -> SRE_Pattern: ... def getcodesize() -> int: ... diff --git a/stdlib/2/heapq.pyi b/stdlib/2/heapq.pyi index 488221c7c..0e706c5f6 100644 --- a/stdlib/2/heapq.pyi +++ b/stdlib/2/heapq.pyi @@ -7,12 +7,10 @@ class _Sortable(Protocol): def cmp_lt(x, y) -> bool: ... def heappush(heap: List[_T], item: _T) -> None: ... -def heappop(heap: List[_T]) -> _T: - raise IndexError() # if heap is empty +def heappop(heap: List[_T]) -> _T: ... def heappushpop(heap: List[_T], item: _T) -> _T: ... def heapify(x: List[_T]) -> None: ... -def heapreplace(heap: List[_T], item: _T) -> _T: - raise IndexError() # if heap is empty +def heapreplace(heap: List[_T], item: _T) -> _T: ... def merge(*iterables: Iterable[_T]) -> Iterable[_T]: ... def nlargest(n: int, iterable: Iterable[_T], key: Optional[Callable[[_T], _Sortable]] = ...) -> List[_T]: ... diff --git a/stdlib/2/posix.pyi b/stdlib/2/posix.pyi index c6ff52ccf..6cfd8520a 100644 --- a/stdlib/2/posix.pyi +++ b/stdlib/2/posix.pyi @@ -113,10 +113,8 @@ def fchmod(fd: int, mode: int) -> None: ... def fchown(fd: int, uid: int, gid: int) -> None: ... def fdatasync(fd: int) -> None: ... def fdopen(fd: int, mode: str = ..., bufsize: int = ...) -> IO[str]: ... -def fork() -> int: - raise OSError() -def forkpty() -> Tuple[int, int]: - raise OSError() +def fork() -> int: ... +def forkpty() -> Tuple[int, int]: ... def fpathconf(fd: int, name: str) -> None: ... def fstat(fd: int) -> stat_result: ... def fstatvfs(fd: int) -> statvfs_result: ... @@ -128,8 +126,7 @@ def getegid() -> int: ... def geteuid() -> int: ... def getgid() -> int: ... def getgroups() -> List[int]: ... -def getloadavg() -> Tuple[float, float, float]: - raise OSError() +def getloadavg() -> Tuple[float, float, float]: ... def getlogin() -> str: ... def getpgid(pid: int) -> int: ... def getpgrp() -> int: ... @@ -195,12 +192,10 @@ def uname() -> Tuple[str, str, str, str, str]: ... def unlink(path: unicode) -> None: ... def unsetenv(varname: str) -> None: ... def urandom(n: int) -> str: ... -def utime(path: unicode, times: Optional[Tuple[int, int]]) -> None: - raise OSError +def utime(path: unicode, times: Optional[Tuple[int, int]]) -> None: ... def wait() -> int: ... _r = Tuple[float, float, int, int, int, int, int, int, int, int, int, int, int, int, int, int] def wait3(options: int) -> Tuple[int, int, _r]: ... def wait4(pid: int, options: int) -> Tuple[int, int, _r]: ... -def waitpid(pid: int, options: int) -> int: - raise OSError() +def waitpid(pid: int, options: int) -> int: ... def write(fd: int, str: str) -> int: ... diff --git a/stdlib/2/signal.pyi b/stdlib/2/signal.pyi index cda4c65ec..24bfbf077 100644 --- a/stdlib/2/signal.pyi +++ b/stdlib/2/signal.pyi @@ -63,9 +63,6 @@ def pause() -> None: ... def setitimer(which: int, seconds: float, interval: float = ...) -> Tuple[float, float]: ... def getitimer(which: int) -> Tuple[float, float]: ... def set_wakeup_fd(fd: int) -> int: ... -def siginterrupt(signalnum: int, flag: bool) -> None: - raise RuntimeError() -def signal(signalnum: int, handler: _HANDLER) -> _HANDLER: - raise RuntimeError() -def default_int_handler(signum: int, frame: FrameType) -> None: - raise KeyboardInterrupt() +def siginterrupt(signalnum: int, flag: bool) -> None: ... +def signal(signalnum: int, handler: _HANDLER) -> _HANDLER: ... +def default_int_handler(signum: int, frame: FrameType) -> None: ... diff --git a/stdlib/2/string.pyi b/stdlib/2/string.pyi index 624f092b3..bf55e922a 100644 --- a/stdlib/2/string.pyi +++ b/stdlib/2/string.pyi @@ -68,10 +68,7 @@ class Formatter(object): def parse(self, format_string: str) -> Iterable[Tuple[str, str, str, str]]: ... def get_field(self, field_name: str, args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any: ... - def get_value(self, key: Union[int, str], args: Sequence[Any], - kwargs: Mapping[str, Any]) -> Any: - raise IndexError() - raise KeyError() + def get_value(self, key: Union[int, str], args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any: ... def check_unused_args(self, used_args: Sequence[Union[int, str]], args: Sequence[Any], kwargs: Mapping[str, Any]) -> None: ... def format_field(self, value: Any, format_spec: str) -> Any: ... diff --git a/stdlib/2/strop.pyi b/stdlib/2/strop.pyi index e1a098fe5..578a47758 100644 --- a/stdlib/2/strop.pyi +++ b/stdlib/2/strop.pyi @@ -6,67 +6,24 @@ lowercase: str uppercase: str whitespace: str -def atof(a: str) -> float: - raise DeprecationWarning() - -def atoi(a: str, base: int = ...) -> int: - raise DeprecationWarning() - -def atol(a: str, base: int = ...) -> long: - raise DeprecationWarning() - -def capitalize(s: str) -> str: - raise DeprecationWarning() - -def count(s: str, sub: str, start: int = ..., end: int = ...) -> int: - raise DeprecationWarning() - -def expandtabs(string: str, tabsize: int = ...) -> str: - raise DeprecationWarning() - raise OverflowError() - -def find(s: str, sub: str, start: int = ..., end: int = ...) -> int: - raise DeprecationWarning() - -def join(list: Sequence[str], sep: str = ...) -> str: - raise DeprecationWarning() - raise OverflowError() - -def joinfields(list: Sequence[str], sep: str = ...) -> str: - raise DeprecationWarning() - raise OverflowError() - -def lower(s: str) -> str: - raise DeprecationWarning() - -def lstrip(s: str) -> str: - raise DeprecationWarning() - +def atof(a: str) -> float: ... +def atoi(a: str, base: int = ...) -> int: ... +def atol(a: str, base: int = ...) -> long: ... +def capitalize(s: str) -> str: ... +def count(s: str, sub: str, start: int = ..., end: int = ...) -> int: ... +def expandtabs(string: str, tabsize: int = ...) -> str: ... +def find(s: str, sub: str, start: int = ..., end: int = ...) -> int: ... +def join(list: Sequence[str], sep: str = ...) -> str: ... +def joinfields(list: Sequence[str], sep: str = ...) -> str: ... +def lower(s: str) -> str: ... +def lstrip(s: str) -> str: ... def maketrans(frm: str, to: str) -> str: ... - -def replace(s: str, old: str, new: str, maxsplit: int = ...) -> str: - raise DeprecationWarning() - -def rfind(s: str, sub: str, start: int = ..., end: int = ...) -> int: - raise DeprecationWarning() - -def rstrip(s: str) -> str: - raise DeprecationWarning() - -def split(s: str, sep: str, maxsplit: int = ...) -> List[str]: - raise DeprecationWarning() - -def splitfields(s: str, sep: str, maxsplit: int = ...) -> List[str]: - raise DeprecationWarning() - -def strip(s: str) -> str: - raise DeprecationWarning() - -def swapcase(s: str) -> str: - raise DeprecationWarning() - -def translate(s: str, table: str, deletechars: str = ...) -> str: - raise DeprecationWarning() - -def upper(s: str) -> str: - raise DeprecationWarning() +def replace(s: str, old: str, new: str, maxsplit: int = ...) -> str: ... +def rfind(s: str, sub: str, start: int = ..., end: int = ...) -> int: ... +def rstrip(s: str) -> str: ... +def split(s: str, sep: str, maxsplit: int = ...) -> List[str]: ... +def splitfields(s: str, sep: str, maxsplit: int = ...) -> List[str]: ... +def strip(s: str) -> str: ... +def swapcase(s: str) -> str: ... +def translate(s: str, table: str, deletechars: str = ...) -> str: ... +def upper(s: str) -> str: ... diff --git a/stdlib/2/sys.pyi b/stdlib/2/sys.pyi index 2b38c6da0..1f5a68fca 100644 --- a/stdlib/2/sys.pyi +++ b/stdlib/2/sys.pyi @@ -114,13 +114,11 @@ def _getframe(depth: int = ...) -> FrameType: ... def call_tracing(fn: Any, args: Any) -> Any: ... def __displayhook__(value: int) -> None: ... def __excepthook__(type_: type, value: BaseException, traceback: TracebackType) -> None: ... -def exc_clear() -> None: - raise DeprecationWarning() +def exc_clear() -> None: ... def exc_info() -> _OptExcInfo: ... # sys.exit() accepts an optional argument of anything printable -def exit(arg: Any = ...) -> NoReturn: - raise SystemExit() +def exit(arg: Any = ...) -> NoReturn: ... def getcheckinterval() -> int: ... # deprecated def getdefaultencoding() -> str: ... def getdlopenflags() -> int: ... diff --git a/stdlib/2/thread.pyi b/stdlib/2/thread.pyi index eb4e6d6d3..5bc40f4ba 100644 --- a/stdlib/2/thread.pyi +++ b/stdlib/2/thread.pyi @@ -21,10 +21,8 @@ class _localdummy(object): ... def start_new(function: Callable[..., Any], args: Any, kwargs: Any = ...) -> int: ... def start_new_thread(function: Callable[..., Any], args: Any, kwargs: Any = ...) -> int: ... def interrupt_main() -> None: ... -def exit() -> None: - raise SystemExit() -def exit_thread() -> Any: - raise SystemExit() +def exit() -> None: ... +def exit_thread() -> Any: ... def allocate_lock() -> LockType: ... def get_ident() -> int: ... def stack_size(size: int = ...) -> int: ... diff --git a/stdlib/2and3/_heapq.pyi b/stdlib/2and3/_heapq.pyi index 9ff4a08fe..2fc4e048b 100644 --- a/stdlib/2and3/_heapq.pyi +++ b/stdlib/2and3/_heapq.pyi @@ -6,12 +6,10 @@ import sys _T = TypeVar("_T") def heapify(heap: List[_T]) -> None: ... -def heappop(heap: List[_T]) -> _T: - raise IndexError() # if list is empty +def heappop(heap: List[_T]) -> _T: ... def heappush(heap: List[_T], item: _T) -> None: ... def heappushpop(heap: List[_T], item: _T) -> _T: ... -def heapreplace(heap: List[_T], item: _T) -> _T: - raise IndexError() # if list is empty +def heapreplace(heap: List[_T], item: _T) -> _T: ... if sys.version_info < (3,): def nlargest(n: int, iterable: Iterable[_T]) -> List[_T]: ... def nsmallest(n: int, iterable: Iterable[_T]) -> List[_T]: ... diff --git a/stdlib/3/_tracemalloc.pyi b/stdlib/3/_tracemalloc.pyi index a46db2419..e8a7168a3 100644 --- a/stdlib/3/_tracemalloc.pyi +++ b/stdlib/3/_tracemalloc.pyi @@ -6,21 +6,11 @@ from typing import Any, Tuple def _get_object_traceback(*args, **kwargs) -> Any: ... - -def _get_traces() -> Any: - raise MemoryError() - +def _get_traces() -> Any: ... def clear_traces() -> None: ... - def get_traceback_limit() -> int: ... - def get_traced_memory() -> Tuple[Any, ...]: ... - def get_tracemalloc_memory() -> Any: ... - def is_tracing() -> bool: ... - -def start(*args, **kwargs) -> None: - raise ValueError() - +def start(*args, **kwargs) -> None: ... def stop() -> None: ... diff --git a/stdlib/3/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index 46d3644dc..400c3dc3d 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -220,18 +220,15 @@ class deque(MutableSequence[_T], Generic[_T]): @overload def __getitem__(self, index: int) -> _T: ... @overload - def __getitem__(self, s: slice) -> MutableSequence[_T]: - raise TypeError + def __getitem__(self, s: slice) -> MutableSequence[_T]: ... @overload def __setitem__(self, i: int, x: _T) -> None: ... @overload - def __setitem__(self, s: slice, o: Iterable[_T]) -> None: - raise TypeError + def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... @overload def __delitem__(self, i: int) -> None: ... @overload - def __delitem__(self, s: slice) -> None: - raise TypeError + def __delitem__(self, s: slice) -> None: ... def __contains__(self, o: object) -> bool: ... def __reversed__(self) -> Iterator[_T]: ... diff --git a/stdlib/3/signal.pyi b/stdlib/3/signal.pyi index 670567b83..dd457d8cc 100644 --- a/stdlib/3/signal.pyi +++ b/stdlib/3/signal.pyi @@ -132,42 +132,17 @@ class struct_siginfo(Tuple[int, int, int, int, int, int, int]): def si_band(self) -> int: ... def alarm(time: int) -> int: ... - -def default_int_handler(signum: int, frame: FrameType) -> None: - raise KeyboardInterrupt() - +def default_int_handler(signum: int, frame: FrameType) -> None: ... def getitimer(which: int) -> Tuple[float, float]: ... - -def getsignal(signalnum: _SIGNUM) -> _HANDLER: - raise ValueError() - +def getsignal(signalnum: _SIGNUM) -> _HANDLER: ... def pause() -> None: ... - -def pthread_kill(thread_id: int, signum: int) -> None: - raise OSError() - -def pthread_sigmask(how: int, mask: Iterable[int]) -> Set[_SIGNUM]: - raise OSError() - +def pthread_kill(thread_id: int, signum: int) -> None: ... +def pthread_sigmask(how: int, mask: Iterable[int]) -> Set[_SIGNUM]: ... def set_wakeup_fd(fd: int) -> int: ... - def setitimer(which: int, seconds: float, interval: float = ...) -> Tuple[float, float]: ... - -def siginterrupt(signalnum: int, flag: bool) -> None: - raise OSError() - -def signal(signalnum: _SIGNUM, handler: _HANDLER) -> _HANDLER: - raise OSError() - -def sigpending() -> Any: - raise OSError() - -def sigtimedwait(sigset: Iterable[int], timeout: float) -> Optional[struct_siginfo]: - raise OSError() - raise ValueError() - -def sigwait(sigset: Iterable[int]) -> _SIGNUM: - raise OSError() - -def sigwaitinfo(sigset: Iterable[int]) -> struct_siginfo: - raise OSError() +def siginterrupt(signalnum: int, flag: bool) -> None: ... +def signal(signalnum: _SIGNUM, handler: _HANDLER) -> _HANDLER: ... +def sigpending() -> Any: ... +def sigtimedwait(sigset: Iterable[int], timeout: float) -> Optional[struct_siginfo]: ... +def sigwait(sigset: Iterable[int]) -> _SIGNUM: ... +def sigwaitinfo(sigset: Iterable[int]) -> struct_siginfo: ... diff --git a/stdlib/3/string.pyi b/stdlib/3/string.pyi index c5b1ff9f8..db437d95a 100644 --- a/stdlib/3/string.pyi +++ b/stdlib/3/string.pyi @@ -32,10 +32,7 @@ class Formatter: def parse(self, format_string: str) -> Iterable[Tuple[str, Optional[str], Optional[str], Optional[str]]]: ... def get_field(self, field_name: str, args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any: ... - def get_value(self, key: Union[int, str], args: Sequence[Any], - kwargs: Mapping[str, Any]) -> Any: - raise IndexError() - raise KeyError() + def get_value(self, key: Union[int, str], args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any: ... def check_unused_args(self, used_args: Sequence[Union[int, str]], args: Sequence[Any], kwargs: Mapping[str, Any]) -> None: ... def format_field(self, value: Any, format_spec: str) -> Any: ... diff --git a/stdlib/3/sys.pyi b/stdlib/3/sys.pyi index 48644328d..6c2fda171 100644 --- a/stdlib/3/sys.pyi +++ b/stdlib/3/sys.pyi @@ -135,8 +135,7 @@ def excepthook(type_: Type[BaseException], value: BaseException, traceback: TracebackType) -> None: ... def exc_info() -> _OptExcInfo: ... # sys.exit() accepts an optional argument of anything printable -def exit(arg: object = ...) -> NoReturn: - raise SystemExit() +def exit(arg: object = ...) -> NoReturn: ... def getcheckinterval() -> int: ... # deprecated def getdefaultencoding() -> str: ... if sys.platform != 'win32':