import dis, traceback, sys def foo(it): return iter(it) def bar(it): return (yield from it) def test(f): dis.dis(f) def i(): yield 1 raise RuntimeError try: for x in f(i()): pass except: traceback.print_exc(file=sys.stdout) test(foo) test(bar)
Standard input is empty
3 0 LOAD_GLOBAL 0 (iter) 3 LOAD_FAST 0 (it) 6 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 9 RETURN_VALUE Traceback (most recent call last): File "./prog.py", line 12, in test File "./prog.py", line 10, in i RuntimeError 5 0 LOAD_FAST 0 (it) 3 GET_ITER 4 LOAD_CONST 0 (None) 7 YIELD_FROM 8 RETURN_VALUE Traceback (most recent call last): File "./prog.py", line 12, in test File "./prog.py", line 5, in bar File "./prog.py", line 10, in i RuntimeError