]> granicus.if.org Git - python/commitdiff
Issue #26136: Upgrade the generator_stop warning to DeprecationWarning
authorMartin Panter <vadmium+py@gmail.com>
Wed, 10 Feb 2016 04:40:48 +0000 (04:40 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Wed, 10 Feb 2016 04:40:48 +0000 (04:40 +0000)
Patch by Anish Shah.

Doc/whatsnew/3.6.rst
Lib/test/test_contextlib.py
Lib/test/test_generators.py
Lib/test/test_with.py
Misc/NEWS
Objects/genobject.c

index 87199df32bf6384af0b1df70926a86e4f3fb9f95..3822d015bb8ecc41d7103347a5c9d07a490879fd 100644 (file)
@@ -234,6 +234,14 @@ Deprecated features
   (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
 =======
 
index 30a6377bed89222facc99035cda5716b704f16dd..04fc875e5fecb70c33e25d385766aece43e6b415 100644 (file)
@@ -89,7 +89,7 @@ class ContextManagerTestCase(unittest.TestCase):
         def woohoo():
             yield
         try:
-            with self.assertWarnsRegex(PendingDeprecationWarning,
+            with self.assertWarnsRegex(DeprecationWarning,
                                        "StopIteration"):
                 with woohoo():
                     raise stop_exc
index b92d5ceeb96bd2a472b39e1ff2cf1b853afde6d0..0389b48f4e916daa8fe4442f921fd6ff863902a3 100644 (file)
@@ -245,11 +245,11 @@ class ExceptionTest(unittest.TestCase):
             yield
 
         with self.assertRaises(StopIteration), \
-             self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
+             self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
 
             next(gen())
 
-        with self.assertRaisesRegex(PendingDeprecationWarning,
+        with self.assertRaisesRegex(DeprecationWarning,
                                     "generator .* raised StopIteration"), \
              warnings.catch_warnings():
 
@@ -268,7 +268,7 @@ class ExceptionTest(unittest.TestCase):
         g = f()
         self.assertEqual(next(g), 1)
 
-        with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
+        with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
             with self.assertRaises(StopIteration):
                 next(g)
 
index e8d789bc2cdf86740012f9be0726a2a9842c77c3..3815062a588df901641b4eaae4c209f45ca00375 100644 (file)
@@ -454,7 +454,7 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase):
             with cm():
                 raise StopIteration("from with")
 
-        with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
+        with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
             self.assertRaises(StopIteration, shouldThrow)
 
     def testRaisedStopIteration2(self):
@@ -482,7 +482,7 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase):
             with cm():
                 raise next(iter([]))
 
-        with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
+        with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
             self.assertRaises(StopIteration, shouldThrow)
 
     def testRaisedGeneratorExit1(self):
index 6ce7e2d15d21aff24b335054616adae5eb807b58..79127903d65834aaee62fd1359c4ff8e092a2de1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ Release date: tba
 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,
   int, float, complex, name constants (None, False, True), Ellipsis
   and ast.Constant; not only str and int. For example, ``1.0`` is now ignored
index 81a80b7ea76661e91c649202453e437f7f64c964..8ab7cf1a41f0c275119459c74be3a33cdba4c4e9 100644 (file)
@@ -178,7 +178,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc)
             /* Pop the exception before issuing a warning. */
             PyErr_Fetch(&exc, &val, &tb);
 
-            if (PyErr_WarnFormat(PyExc_PendingDeprecationWarning, 1,
+            if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                                  "generator '%.50S' raised StopIteration",
                                  gen->gi_qualname)) {
                 /* Warning was converted to an error. */