From 30d67e5aaa3bc6fc838733b26fccf3dc82f708ec Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Wed, 14 May 2008 21:58:07 +0200 Subject: [PATCH] Fixed iterator raising exception bug. Simply a typo in NextNode... --- Cython/Compiler/ExprNodes.py | 2 +- tests/run/iteratorexception.pyx | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/run/iteratorexception.pyx diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 2a95b4f2..47b94ba6 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1197,7 +1197,7 @@ class NextNode(AtomicExprNode): code.putln( "if (!%s) {" % self.result_code) - code.error_goto_if_PyErr(self.pos) + code.putln(code.error_goto_if_PyErr(self.pos)) code.putln("break;") code.putln("}") code.putln("}") diff --git a/tests/run/iteratorexception.pyx b/tests/run/iteratorexception.pyx new file mode 100644 index 00000000..98f9806f --- /dev/null +++ b/tests/run/iteratorexception.pyx @@ -0,0 +1,17 @@ +__doc__ = """ + >>> f() +""" + +class IteratorAndIterateable: + def next(self): + raise ValueError("") + def __iter__(self): + return self + +def f(): + try: + for x in IteratorAndIterateable(): + pass + assert False, "Should not reach this point, iterator has thrown exception" + except ValueError: + pass -- 2.26.2