Fix issue #1705170 (backport from trunk)
This commit is contained in:
parent
2e49f781cb
commit
e53fcfd7d3
|
@ -25,6 +25,10 @@ class GeneratorContextManager(object):
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("generator didn't stop")
|
raise RuntimeError("generator didn't stop")
|
||||||
else:
|
else:
|
||||||
|
if value is None:
|
||||||
|
# Need to force instantiation so we can reliably
|
||||||
|
# tell if we get the same exception back
|
||||||
|
value = type()
|
||||||
try:
|
try:
|
||||||
self.gen.throw(type, value, traceback)
|
self.gen.throw(type, value, traceback)
|
||||||
raise RuntimeError("generator didn't stop after throw()")
|
raise RuntimeError("generator didn't stop after throw()")
|
||||||
|
|
|
@ -440,6 +440,7 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
|
||||||
self.assertAfterWithGeneratorInvariantsNoError(self.bar)
|
self.assertAfterWithGeneratorInvariantsNoError(self.bar)
|
||||||
|
|
||||||
def testRaisedStopIteration1(self):
|
def testRaisedStopIteration1(self):
|
||||||
|
# From bug 1462485
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def cm():
|
def cm():
|
||||||
yield
|
yield
|
||||||
|
@ -451,6 +452,7 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
|
||||||
self.assertRaises(StopIteration, shouldThrow)
|
self.assertRaises(StopIteration, shouldThrow)
|
||||||
|
|
||||||
def testRaisedStopIteration2(self):
|
def testRaisedStopIteration2(self):
|
||||||
|
# From bug 1462485
|
||||||
class cm(object):
|
class cm(object):
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
pass
|
pass
|
||||||
|
@ -463,7 +465,21 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
|
||||||
|
|
||||||
self.assertRaises(StopIteration, shouldThrow)
|
self.assertRaises(StopIteration, shouldThrow)
|
||||||
|
|
||||||
|
def testRaisedStopIteration3(self):
|
||||||
|
# Another variant where the exception hasn't been instantiated
|
||||||
|
# From bug 1705170
|
||||||
|
@contextmanager
|
||||||
|
def cm():
|
||||||
|
yield
|
||||||
|
|
||||||
|
def shouldThrow():
|
||||||
|
with cm():
|
||||||
|
raise iter([]).next()
|
||||||
|
|
||||||
|
self.assertRaises(StopIteration, shouldThrow)
|
||||||
|
|
||||||
def testRaisedGeneratorExit1(self):
|
def testRaisedGeneratorExit1(self):
|
||||||
|
# From bug 1462485
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def cm():
|
def cm():
|
||||||
yield
|
yield
|
||||||
|
@ -475,6 +491,7 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
|
||||||
self.assertRaises(GeneratorExit, shouldThrow)
|
self.assertRaises(GeneratorExit, shouldThrow)
|
||||||
|
|
||||||
def testRaisedGeneratorExit2(self):
|
def testRaisedGeneratorExit2(self):
|
||||||
|
# From bug 1462485
|
||||||
class cm (object):
|
class cm (object):
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -32,6 +32,9 @@ Core and builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #1705170: contextlib.contextmanager was still swallowing
|
||||||
|
StopIteration in some cases. This should no longer happen.
|
||||||
|
|
||||||
- Bug #1307: Fix smtpd so it doesn't raise an exception when there is no arg.
|
- Bug #1307: Fix smtpd so it doesn't raise an exception when there is no arg.
|
||||||
|
|
||||||
- ctypes will now work correctly on 32-bit systems when Python is
|
- ctypes will now work correctly on 32-bit systems when Python is
|
||||||
|
|
Loading…
Reference in New Issue