From 14d28be344702b98f2694e245ed4a00c86f898c2 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 27 Jan 2014 01:01:37 +0200 Subject: gen.send(): Throw StopIteration. Also, explicitly shutdown finished gen. Otherwise, some generator statements still may be spuriously executed on subsequent calls to next()/send(). --- tests/basics/generator_send.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/basics/generator_send.py') 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") -- cgit v1.2.3