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.
This commit is contained in:
Richard Hansen
2017-03-14 12:35:06 -04:00
committed by Guido van Rossum
parent 9899037be9
commit 1abd14bbcd

View File

@@ -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]: ...