asyncio: Future.set_exception(exc) should instantiate exc if it is a class.
This commit is contained in:
parent
91445fbeb0
commit
9572898282
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue