[Python-checkins] cpython: Issue #26136: Upgrade the generator_stop warning to DeprecationWarning

martin.panter python-checkins at python.org
Wed Feb 10 00:22:29 EST 2016


https://hg.python.org/cpython/rev/73f89182bb4d
changeset:   100209:73f89182bb4d
user:        Martin Panter <vadmium+py at gmail.com>
date:        Wed Feb 10 04:40:48 2016 +0000
summary:
  Issue #26136: Upgrade the generator_stop warning to DeprecationWarning

Patch by Anish Shah.

files:
  Doc/whatsnew/3.6.rst        |  8 ++++++++
  Lib/test/test_contextlib.py |  2 +-
  Lib/test/test_generators.py |  6 +++---
  Lib/test/test_with.py       |  4 ++--
  Misc/NEWS                   |  4 ++++
  Objects/genobject.c         |  2 +-
  6 files changed, 19 insertions(+), 7 deletions(-)


diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst
--- a/Doc/whatsnew/3.6.rst
+++ b/Doc/whatsnew/3.6.rst
@@ -234,6 +234,14 @@
   (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
 =======
 
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -89,7 +89,7 @@
         def woohoo():
             yield
         try:
-            with self.assertWarnsRegex(PendingDeprecationWarning,
+            with self.assertWarnsRegex(DeprecationWarning,
                                        "StopIteration"):
                 with woohoo():
                     raise stop_exc
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -245,11 +245,11 @@
             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 @@
         g = f()
         self.assertEqual(next(g), 1)
 
-        with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
+        with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
             with self.assertRaises(StopIteration):
                 next(g)
 
diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py
--- a/Lib/test/test_with.py
+++ b/Lib/test/test_with.py
@@ -454,7 +454,7 @@
             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 @@
             with cm():
                 raise next(iter([]))
 
-        with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
+        with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
             self.assertRaises(StopIteration, shouldThrow)
 
     def testRaisedGeneratorExit1(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
 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
diff --git a/Objects/genobject.c b/Objects/genobject.c
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -178,7 +178,7 @@
             /* 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. */

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


More information about the Python-checkins mailing list