diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-27 01:01:37 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-27 01:07:58 +0200 |
commit | 14d28be344702b98f2694e245ed4a00c86f898c2 (patch) | |
tree | f69239397516eeb06d1ab07be15aaf18815dcc02 /tests/basics/generator_send.py | |
parent | addf60b2e6176d8cce23c5608dee10ce196db94b (diff) | |
download | micropython-14d28be344702b98f2694e245ed4a00c86f898c2.tar.gz micropython-14d28be344702b98f2694e245ed4a00c86f898c2.zip |
gen.send(): Throw StopIteration. Also, explicitly shutdown finished gen.
Otherwise, some generator statements still may be spuriously executed on
subsequent calls to next()/send().
Diffstat (limited to 'tests/basics/generator_send.py')
-rw-r--r-- | tests/basics/generator_send.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/basics/generator_send.py b/tests/basics/generator_send.py index 4158478cac..c472c31ba9 100644 --- a/tests/basics/generator_send.py +++ b/tests/basics/generator_send.py @@ -13,3 +13,25 @@ except TypeError: print(g.send(None)) print(g.send(100)) print(g.send(200)) + + +def f2(): + print("entering") + for i in range(3): + print(i) + yield + print("returning 1") + print("returning 2") + +g = f2() +g.send(None) +g.send(1) +g.send(1) +try: + g.send(1) +except StopIteration: + print("caught") +try: + g.send(1) +except StopIteration: + print("caught") |