diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-29 12:18:14 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-29 12:18:14 +0000 |
commit | da51a399cf628699546f77f320ef0388a268b49f (patch) | |
tree | 44e842786517ed39a8738e24da605160c46edcf3 /tests/basics/gen-yield-from.py | |
parent | 75f71584a67b3aa8ad03762547ac6441551c63ca (diff) | |
parent | 3c2b2acd8c21294d046f4d2ef9195a976a5ef999 (diff) | |
download | micropython-da51a399cf628699546f77f320ef0388a268b49f.tar.gz micropython-da51a399cf628699546f77f320ef0388a268b49f.zip |
Merge pull request #383 from pfalcon/yield-from
Implement "yield from"
Diffstat (limited to 'tests/basics/gen-yield-from.py')
-rw-r--r-- | tests/basics/gen-yield-from.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/basics/gen-yield-from.py b/tests/basics/gen-yield-from.py new file mode 100644 index 0000000000..5196b48d2b --- /dev/null +++ b/tests/basics/gen-yield-from.py @@ -0,0 +1,42 @@ +# Case of terminating subgen using return with value +def gen(): + yield 1 + yield 2 + return 3 + +def gen2(): + print("here1") + print((yield from gen())) + print("here2") + +g = gen2() +print(list(g)) + + +# Like above, but terminate subgen using StopIteration +def gen3(): + yield 1 + yield 2 + raise StopIteration + +def gen4(): + print("here1") + print((yield from gen3())) + print("here2") + +g = gen4() +print(list(g)) + +# Like above, but terminate subgen using StopIteration with value +def gen5(): + yield 1 + yield 2 + raise StopIteration(123) + +def gen6(): + print("here1") + print((yield from gen5())) + print("here2") + +g = gen6() +print(list(g)) |