Issue 24237: Raise PendingDeprecationWarning per PEP 479

Raise PendingDeprecationWarning when generator raises StopIteration
and no __future__ import is used.  Fix offenders in the stdlib
and tests.

See also issue 22906.
Thanks to Nick Coghlan and Berker Peksag for reviews.
This commit is contained in:
Yury Selivanov 2015-05-22 11:16:47 -04:00
parent e79ec70801
commit 683333955a
5 changed files with 78 additions and 29 deletions

View file

@ -454,7 +454,8 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase):
with cm():
raise StopIteration("from with")
self.assertRaises(StopIteration, shouldThrow)
with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
self.assertRaises(StopIteration, shouldThrow)
def testRaisedStopIteration2(self):
# From bug 1462485
@ -481,7 +482,8 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase):
with cm():
raise next(iter([]))
self.assertRaises(StopIteration, shouldThrow)
with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
self.assertRaises(StopIteration, shouldThrow)
def testRaisedGeneratorExit1(self):
# From bug 1462485