From 1abd14bbcdd9a3c38bd8b964f9c3261e9a39d31e Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 14 Mar 2017 12:35:06 -0400 Subject: [PATCH] Allow old-style exception types for backported Future. (#946) third_party/2/concurrent/futures is for the Python 2 backport of the concurrent.futures package from Python 3. In Python 3, all exceptions are derived from BaseException, but Python 2 also supports exceptions that are old-style objects (which don't derive from BaseException). Switch from BaseException to Any to allow old-style exceptions. All old-style objects are instances of types.InstanceType, so an alternative to Any is Union[BaseException, types.InstanceType]. This would help avoid accidentally passing a non-BaseException new-style object to Future.set_exception(). However, only Executors call that function (usually), and it's not clear that mypy understands old-style objects and their relationship to types.InstanceType, so Any is thought to be the more practical choice. --- third_party/2/concurrent/futures/__init__.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/2/concurrent/futures/__init__.pyi b/third_party/2/concurrent/futures/__init__.pyi index 5e5888876..bbec6ad67 100644 --- a/third_party/2/concurrent/futures/__init__.pyi +++ b/third_party/2/concurrent/futures/__init__.pyi @@ -12,12 +12,12 @@ class Future(Generic[_T]): def running(self) -> bool: ... def done(self) -> bool: ... def result(self, timeout: float = ...) -> _T: ... - def exception(self, timeout: float = ...) -> BaseException: ... + def exception(self, timeout: float = ...) -> Any: ... def add_done_callback(self, fn: Callable[[Future], Any]) -> None: ... def set_running_or_notify_cancel(self) -> None: ... def set_result(self, result: _T) -> None: ... - def set_exception(self, exception: BaseException) -> None: ... + def set_exception(self, exception: Any) -> None: ... class Executor: def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...