1# tests for correct PEP479 behaviour (introduced in Python 3.5)
2
3# basic case: StopIteration is converted into a RuntimeError
4def gen():
5    yield 1
6    raise StopIteration
7g = gen()
8print(next(g))
9try:
10    next(g)
11except RuntimeError:
12    print('RuntimeError')
13
14# trying to continue a failed generator now raises StopIteration
15try:
16    next(g)
17except StopIteration:
18    print('StopIteration')
19
20# throwing a StopIteration which is uncaught will be converted into a RuntimeError
21def gen():
22    yield 1
23    yield 2
24g = gen()
25print(next(g))
26try:
27    g.throw(StopIteration)
28except RuntimeError:
29    print('RuntimeError')
30
31# throwing a StopIteration through yield from, will be converted to a RuntimeError
32def gen():
33    yield from range(2)
34    print('should not get here')
35g = gen()
36print(next(g))
37try:
38    g.throw(StopIteration)
39except RuntimeError:
40    print('RuntimeError')
41