Commit 7e3a91a5 authored by Martin Panter's avatar Martin Panter

Issue #26136: Upgrade the generator_stop warning to DeprecationWarning

Patch by Anish Shah.
parent b0cb42df
...@@ -234,6 +234,14 @@ Deprecated features ...@@ -234,6 +234,14 @@ Deprecated features
(Contributed by Rose Ames in :issue:`25791`.) (Contributed by Rose Ames in :issue:`25791`.)
Deprecated Python behavior
--------------------------
* Raising the :exc:`StopIteration` exception inside a generator will now generate a
:exc:`DeprecationWarning`, and will trigger a :exc:`RuntimeError` in Python 3.7.
See :ref:`whatsnew-pep-479` for details.
Removed Removed
======= =======
......
...@@ -89,7 +89,7 @@ class ContextManagerTestCase(unittest.TestCase): ...@@ -89,7 +89,7 @@ class ContextManagerTestCase(unittest.TestCase):
def woohoo(): def woohoo():
yield yield
try: try:
with self.assertWarnsRegex(PendingDeprecationWarning, with self.assertWarnsRegex(DeprecationWarning,
"StopIteration"): "StopIteration"):
with woohoo(): with woohoo():
raise stop_exc raise stop_exc
......
...@@ -245,11 +245,11 @@ class ExceptionTest(unittest.TestCase): ...@@ -245,11 +245,11 @@ class ExceptionTest(unittest.TestCase):
yield yield
with self.assertRaises(StopIteration), \ with self.assertRaises(StopIteration), \
self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"): self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
next(gen()) next(gen())
with self.assertRaisesRegex(PendingDeprecationWarning, with self.assertRaisesRegex(DeprecationWarning,
"generator .* raised StopIteration"), \ "generator .* raised StopIteration"), \
warnings.catch_warnings(): warnings.catch_warnings():
...@@ -268,7 +268,7 @@ class ExceptionTest(unittest.TestCase): ...@@ -268,7 +268,7 @@ class ExceptionTest(unittest.TestCase):
g = f() g = f()
self.assertEqual(next(g), 1) self.assertEqual(next(g), 1)
with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"): with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
next(g) next(g)
......
...@@ -454,7 +454,7 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase): ...@@ -454,7 +454,7 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase):
with cm(): with cm():
raise StopIteration("from with") raise StopIteration("from with")
with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"): with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
self.assertRaises(StopIteration, shouldThrow) self.assertRaises(StopIteration, shouldThrow)
def testRaisedStopIteration2(self): def testRaisedStopIteration2(self):
...@@ -482,7 +482,7 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase): ...@@ -482,7 +482,7 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase):
with cm(): with cm():
raise next(iter([])) raise next(iter([]))
with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"): with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
self.assertRaises(StopIteration, shouldThrow) self.assertRaises(StopIteration, shouldThrow)
def testRaisedGeneratorExit1(self): def testRaisedGeneratorExit1(self):
......
...@@ -10,6 +10,10 @@ Release date: tba ...@@ -10,6 +10,10 @@ Release date: tba
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #26136: Upgrade the warning when a generator raises StopIteration
from PendingDeprecationWarning to DeprecationWarning. Patch by Anish
Shah.
- Issue #26204: The compiler now ignores all constant statements: bytes, str, - Issue #26204: The compiler now ignores all constant statements: bytes, str,
int, float, complex, name constants (None, False, True), Ellipsis int, float, complex, name constants (None, False, True), Ellipsis
and ast.Constant; not only str and int. For example, ``1.0`` is now ignored and ast.Constant; not only str and int. For example, ``1.0`` is now ignored
......
...@@ -178,7 +178,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc) ...@@ -178,7 +178,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc)
/* Pop the exception before issuing a warning. */ /* Pop the exception before issuing a warning. */
PyErr_Fetch(&exc, &val, &tb); PyErr_Fetch(&exc, &val, &tb);
if (PyErr_WarnFormat(PyExc_PendingDeprecationWarning, 1, if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"generator '%.50S' raised StopIteration", "generator '%.50S' raised StopIteration",
gen->gi_qualname)) { gen->gi_qualname)) {
/* Warning was converted to an error. */ /* Warning was converted to an error. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment