(original) (raw)
changeset: 100395:5e2f7e51af51 parent: 100393:e3aee2f16937 parent: 100394:ef5265bc07bb user: Yury Selivanov yselivanov@sprymix.com date: Wed Mar 02 11:03:53 2016 -0500 description: Merge 3.5 (issue #26221) diff -r e3aee2f16937 -r 5e2f7e51af51 Lib/asyncio/futures.py --- a/Lib/asyncio/futures.py Wed Mar 02 10:49:36 2016 -0500 +++ b/Lib/asyncio/futures.py Wed Mar 02 11:03:53 2016 -0500 @@ -341,6 +341,9 @@ raise InvalidStateError('{}: {!r}'.format(self._state, self)) if isinstance(exception, type): exception = exception() + if type(exception) is StopIteration: + raise TypeError("StopIteration interacts badly with generators " + "and cannot be raised into a Future") self._exception = exception self._state = _FINISHED self._schedule_callbacks() diff -r e3aee2f16937 -r 5e2f7e51af51 Lib/test/test_asyncio/test_futures.py --- a/Lib/test/test_asyncio/test_futures.py Wed Mar 02 10:49:36 2016 -0500 +++ b/Lib/test/test_asyncio/test_futures.py Wed Mar 02 11:03:53 2016 -0500 @@ -76,6 +76,10 @@ f = asyncio.Future(loop=self.loop) self.assertRaises(asyncio.InvalidStateError, f.exception) + # StopIteration cannot be raised into a Future - CPython issue26221 + self.assertRaisesRegex(TypeError, "StopIteration .* cannot be raised", + f.set_exception, StopIteration) + f.set_exception(exc) self.assertFalse(f.cancelled()) self.assertTrue(f.done()) /yselivanov@sprymix.com