summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/gen_yield_from_throw2.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-09-28 11:35:37 +1000
committerDamien George <damien.p.george@gmail.com>2018-09-28 11:39:35 +1000
commit0c9d4523705c0b7f156e92611001dfb3ea26424a (patch)
treec2e0cc959e3122dd76bb16dfee2e4feadbe18bbd /tests/basics/gen_yield_from_throw2.py
parente6078dfed21470dd3b0f3a5e33c78b7db3501711 (diff)
downloadmicropython-0c9d4523705c0b7f156e92611001dfb3ea26424a.tar.gz
micropython-0c9d4523705c0b7f156e92611001dfb3ea26424a.zip
py/vm: Fix case of throwing GeneratorExit type into yield-from.
mp_make_raise_obj must be used to convert a possible exception type to an instance object, otherwise the VM may raise a non-exception object. An existing test is adjusted to test this case, with the original test already moved to generator_throw.py.
Diffstat (limited to 'tests/basics/gen_yield_from_throw2.py')
-rw-r--r--tests/basics/gen_yield_from_throw2.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/basics/gen_yield_from_throw2.py b/tests/basics/gen_yield_from_throw2.py
index 0abfdd8cc3..6b59a7835a 100644
--- a/tests/basics/gen_yield_from_throw2.py
+++ b/tests/basics/gen_yield_from_throw2.py
@@ -1,18 +1,24 @@
-# generator ignores a thrown GeneratorExit (this is allowed)
+# outer generator ignores a thrown GeneratorExit (this is allowed)
def gen():
try:
yield 123
except GeneratorExit:
print('GeneratorExit')
- yield 456
-
+
+def gen2():
+ try:
+ yield from gen()
+ except GeneratorExit:
+ print('GeneratorExit outer')
+ yield 789
+
# thrown a class
-g = gen()
+g = gen2()
print(next(g))
print(g.throw(GeneratorExit))
# thrown an instance
-g = gen()
+g = gen2()
print(next(g))
print(g.throw(GeneratorExit()))