From 66a9a4b5ce72aaf022b24706bf58254602ef02f8 Mon Sep 17 00:00:00 2001 From: Milap Sheth Date: Sun, 21 Jun 2020 18:23:28 -0400 Subject: [PATCH] Fix type hint of generator throw method (#4253) * Fix type hint of generator throw method * Incorporated changes from #4252 --- stdlib/2/types.pyi | 8 +++++--- stdlib/2/typing.pyi | 12 +++++++++--- stdlib/3/types.pyi | 24 +++++++++++++++--------- stdlib/3/typing.pyi | 33 ++++++++++++++++++++++++--------- 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/stdlib/2/types.pyi b/stdlib/2/types.pyi index 47c52e88a..63b296b70 100644 --- a/stdlib/2/types.pyi +++ b/stdlib/2/types.pyi @@ -89,11 +89,13 @@ class GeneratorType: def __iter__(self) -> GeneratorType: ... def close(self) -> None: ... def next(self) -> Any: ... - def send(self, arg: Any) -> Any: ... + def send(self, __arg: Any) -> Any: ... @overload - def throw(self, val: BaseException) -> Any: ... + def throw(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., + __tb: Optional[TracebackType] = ...) -> Any: ... @overload - def throw(self, typ: type, val: BaseException = ..., tb: TracebackType = ...) -> Any: ... + def throw(self, __typ: BaseException, __val: None = ..., + __tb: Optional[TracebackType] = ...) -> Any: ... class ClassType: ... class UnboundMethodType: diff --git a/stdlib/2/typing.pyi b/stdlib/2/typing.pyi index 55b91845e..7f677ec85 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -136,11 +136,17 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): def next(self) -> _T_co: ... @abstractmethod - def send(self, value: _T_contra) -> _T_co: ... + def send(self, __value: _T_contra) -> _T_co: ... + @overload @abstractmethod - def throw(self, typ: Type[BaseException], val: Optional[BaseException] = ..., - tb: TracebackType = ...) -> _T_co: ... + def throw(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., + __tb: Optional[TracebackType] = ...) -> _T_co: ... + @overload + @abstractmethod + def throw(self, __typ: BaseException, __val: None = ..., + __tb: Optional[TracebackType] = ...) -> _T_co: ... + @abstractmethod def close(self) -> None: ... @property diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 0f5b05c58..6c1bbfced 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -138,11 +138,13 @@ class GeneratorType: def __iter__(self) -> GeneratorType: ... def __next__(self) -> Any: ... def close(self) -> None: ... - def send(self, arg: Any) -> Any: ... + def send(self, __arg: Any) -> Any: ... @overload - def throw(self, val: BaseException) -> Any: ... + def throw(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., + __tb: Optional[TracebackType] = ...) -> Any: ... @overload - def throw(self, typ: type, val: BaseException = ..., tb: TracebackType = ...) -> Any: ... + def throw(self, __typ: BaseException, __val: None = ..., + __tb: Optional[TracebackType] = ...) -> Any: ... if sys.version_info >= (3, 6): class AsyncGeneratorType(Generic[_T_co, _T_contra]): @@ -152,11 +154,13 @@ if sys.version_info >= (3, 6): ag_code: CodeType def __aiter__(self) -> Awaitable[AsyncGeneratorType[_T_co, _T_contra]]: ... def __anext__(self) -> Awaitable[_T_co]: ... - def asend(self, val: _T_contra) -> Awaitable[_T_co]: ... + def asend(self, __val: _T_contra) -> Awaitable[_T_co]: ... @overload - def athrow(self, val: BaseException) -> Awaitable[_T_co]: ... + def athrow(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., + __tb: Optional[TracebackType] = ...) -> Awaitable[_T_co]: ... @overload - def athrow(self, typ: Type[BaseException], val: BaseException, tb: TracebackType = ...) -> Awaitable[_T_co]: ... + def athrow(self, __typ: BaseException, __val: None = ..., + __tb: Optional[TracebackType] = ...) -> Awaitable[_T_co]: ... def aclose(self) -> Awaitable[None]: ... class CoroutineType: @@ -165,11 +169,13 @@ class CoroutineType: cr_frame: FrameType cr_running: bool def close(self) -> None: ... - def send(self, arg: Any) -> Any: ... + def send(self, __arg: Any) -> Any: ... @overload - def throw(self, val: BaseException) -> Any: ... + def throw(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., + __tb: Optional[TracebackType] = ...) -> Any: ... @overload - def throw(self, typ: type, val: BaseException = ..., tb: TracebackType = ...) -> Any: ... + def throw(self, __typ: BaseException, __val: None = ..., + __tb: Optional[TracebackType] = ...) -> Any: ... class _StaticFunctionType: """Fictional type to correct the type of MethodType.__func__. diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 7e2151eee..fc8ccd763 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -167,11 +167,16 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): def __next__(self) -> _T_co: ... @abstractmethod - def send(self, value: _T_contra) -> _T_co: ... + def send(self, __value: _T_contra) -> _T_co: ... + @overload @abstractmethod - def throw(self, typ: Type[BaseException], val: Optional[BaseException] = ..., - tb: Optional[TracebackType] = ...) -> _T_co: ... + def throw(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., + __tb: Optional[TracebackType] = ...) -> _T_co: ... + @overload + @abstractmethod + def throw(self, __typ: BaseException, __val: None = ..., + __tb: Optional[TracebackType] = ...) -> _T_co: ... @abstractmethod def close(self) -> None: ... @@ -204,11 +209,16 @@ class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): def cr_running(self) -> bool: ... @abstractmethod - def send(self, value: _T_contra) -> _T_co: ... + def send(self, __value: _T_contra) -> _T_co: ... + @overload @abstractmethod - def throw(self, typ: Type[BaseException], val: Optional[BaseException] = ..., - tb: Optional[TracebackType] = ...) -> _T_co: ... + def throw(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., + __tb: Optional[TracebackType] = ...) -> _T_co: ... + @overload + @abstractmethod + def throw(self, __typ: BaseException, __val: None = ..., + __tb: Optional[TracebackType] = ...) -> _T_co: ... @abstractmethod def close(self) -> None: ... @@ -237,11 +247,16 @@ if sys.version_info >= (3, 6): def __anext__(self) -> Awaitable[_T_co]: ... @abstractmethod - def asend(self, value: _T_contra) -> Awaitable[_T_co]: ... + def asend(self, __value: _T_contra) -> Awaitable[_T_co]: ... + @overload @abstractmethod - def athrow(self, typ: Type[BaseException], val: Optional[BaseException] = ..., - tb: Any = ...) -> Awaitable[_T_co]: ... + def athrow(self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., + __tb: Optional[TracebackType] = ...) -> Awaitable[_T_co]: ... + @overload + @abstractmethod + def athrow(self, __typ: BaseException, __val: None = ..., + __tb: Optional[TracebackType] = ...) -> Awaitable[_T_co]: ... @abstractmethod def aclose(self) -> Awaitable[None]: ...