]> granicus.if.org Git - python/commitdiff
asyncio: Future.set_exception(exc) should instantiate exc if it is a class.
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 31 Jan 2014 00:01:54 +0000 (16:01 -0800)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 31 Jan 2014 00:01:54 +0000 (16:01 -0800)
Lib/asyncio/futures.py
Lib/test/test_asyncio/test_futures.py

index 9ee13e3e2b79410fb789de91a98dcdca56dc4a41..d09f423ce4d00735e278d4a222743c6d992b3e2e 100644 (file)
@@ -301,6 +301,8 @@ class Future:
         """
         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()
index d3a741254f87dab1568e74e875c661bcabd0a98e..8a6976b17da538dc9e2510cd29a6c30de38ae473 100644 (file)
@@ -79,6 +79,11 @@ class FutureTests(unittest.TestCase):
         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)