Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e3a91a

Browse files
committed
Issue #26136: Upgrade the generator_stop warning to DeprecationWarning
Patch by Anish Shah.
1 parent b0cb42d commit 7e3a91a

6 files changed

Lines changed: 19 additions & 7 deletions

File tree

Doc/whatsnew/3.6.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ Deprecated features
234234
(Contributed by Rose Ames in :issue:`25791`.)
235235

236236

237+
Deprecated Python behavior
238+
--------------------------
239+
240+
* Raising the :exc:`StopIteration` exception inside a generator will now generate a
241+
:exc:`DeprecationWarning`, and will trigger a :exc:`RuntimeError` in Python 3.7.
242+
See :ref:`whatsnew-pep-479` for details.
243+
244+
237245
Removed
238246
=======
239247

Lib/test/test_contextlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_contextmanager_except_stopiter(self):
8989
def woohoo():
9090
yield
9191
try:
92-
with self.assertWarnsRegex(PendingDeprecationWarning,
92+
with self.assertWarnsRegex(DeprecationWarning,
9393
"StopIteration"):
9494
with woohoo():
9595
raise stop_exc

Lib/test/test_generators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ def gen():
245245
yield
246246

247247
with self.assertRaises(StopIteration), \
248-
self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
248+
self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
249249

250250
next(gen())
251251

252-
with self.assertRaisesRegex(PendingDeprecationWarning,
252+
with self.assertRaisesRegex(DeprecationWarning,
253253
"generator .* raised StopIteration"), \
254254
warnings.catch_warnings():
255255

@@ -268,7 +268,7 @@ def f():
268268
g = f()
269269
self.assertEqual(next(g), 1)
270270

271-
with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
271+
with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
272272
with self.assertRaises(StopIteration):
273273
next(g)
274274

Lib/test/test_with.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def shouldThrow():
454454
with cm():
455455
raise StopIteration("from with")
456456

457-
with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
457+
with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
458458
self.assertRaises(StopIteration, shouldThrow)
459459

460460
def testRaisedStopIteration2(self):
@@ -482,7 +482,7 @@ def shouldThrow():
482482
with cm():
483483
raise next(iter([]))
484484

485-
with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
485+
with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
486486
self.assertRaises(StopIteration, shouldThrow)
487487

488488
def testRaisedGeneratorExit1(self):

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Release date: tba
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #26136: Upgrade the warning when a generator raises StopIteration
14+
from PendingDeprecationWarning to DeprecationWarning. Patch by Anish
15+
Shah.
16+
1317
- Issue #26204: The compiler now ignores all constant statements: bytes, str,
1418
int, float, complex, name constants (None, False, True), Ellipsis
1519
and ast.Constant; not only str and int. For example, ``1.0`` is now ignored

Objects/genobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc)
178178
/* Pop the exception before issuing a warning. */
179179
PyErr_Fetch(&exc, &val, &tb);
180180

181-
if (PyErr_WarnFormat(PyExc_PendingDeprecationWarning, 1,
181+
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
182182
"generator '%.50S' raised StopIteration",
183183
gen->gi_qualname)) {
184184
/* Warning was converted to an error. */

0 commit comments

Comments
 (0)