cpython: asyncio: Future.set_exception(exc) should instantiate exc if it is a class.
http://hg.python.org/cpython/rev/354ddb56cc81 changeset: 88839:354ddb56cc81 parent: 88837:73dbb884eb09 user: Victor Stinner <victor.stinner@gmail.com> date: Thu Jan 30 16:01:54 2014 -0800 summary: asyncio: Future.set_exception(exc) should instantiate exc if it is a class. files: Lib/asyncio/futures.py | 2 ++ Lib/test/test_asyncio/test_futures.py | 5 +++++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py --- a/Lib/asyncio/futures.py +++ b/Lib/asyncio/futures.py @@ -301,6 +301,8 @@ """ if self._state != _PENDING: raise InvalidStateError('{}: {!r}'.format(self._state, self)) + if isinstance(exception, type): + exception = exception() self._exception = exception self._state = _FINISHED self._schedule_callbacks() diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py --- a/Lib/test/test_asyncio/test_futures.py +++ b/Lib/test/test_asyncio/test_futures.py @@ -79,6 +79,11 @@ self.assertRaises(asyncio.InvalidStateError, f.set_exception, None) self.assertFalse(f.cancel()) + def test_exception_class(self): + f = asyncio.Future(loop=self.loop) + f.set_exception(RuntimeError) + self.assertIsInstance(f.exception(), RuntimeError) + def test_yield_from_twice(self): f = asyncio.Future(loop=self.loop) -- Repository URL: http://hg.python.org/cpython
participants (1)
-
guido.van.rossum