Skip to content

Commit 883c217

Browse files
committed
Add test.
1 parent e714de6 commit 883c217

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Lib/test/test_yield_from.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,19 @@ def outer():
15761576
self.assertIsNone(caught.exception.__context__)
15771577
self.assert_stop_iteration(g)
15781578

1579+
def test_throws_in_iter(self):
1580+
# See GH-126366: NULL pointer dereference if __iter__
1581+
# threw an exception.
1582+
class Silly:
1583+
def __iter__(self):
1584+
raise RuntimeError("nobody expects the spanish inquisition")
1585+
1586+
def my_generator():
1587+
yield from Silly()
1588+
1589+
with self.assertRaisesRegex(RuntimeError, "nobody expects the spanish inquisition"):
1590+
next(iter(my_generator()))
1591+
15791592

15801593
if __name__ == '__main__':
15811594
unittest.main()

0 commit comments

Comments
 (0)