[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5 (issue #26221)

yury.selivanov python-checkins at python.org
Wed Mar 2 11:04:08 EST 2016


https://hg.python.org/cpython/rev/5e2f7e51af51
changeset:   100395:5e2f7e51af51
parent:      100393:e3aee2f16937
parent:      100394:ef5265bc07bb
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Wed Mar 02 11:03:53 2016 -0500
summary:
  Merge 3.5 (issue #26221)

files:
  Lib/asyncio/futures.py                |  3 +++
  Lib/test/test_asyncio/test_futures.py |  4 ++++
  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
@@ -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 --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
@@ -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())

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list