From: Stefan Behnel Date: Mon, 25 Apr 2011 05:34:49 +0000 (+0200) Subject: fix function declarations inside of 'with' blocks X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d88716c78588f7825baf5ea9847e4dde8625e30b;p=cython.git fix function declarations inside of 'with' blocks --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 006133c4..51ef88f3 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -4870,6 +4870,10 @@ class WithStatNode(StatNode): self.manager.analyse_types(env) self.body.analyse_expressions(env) + def generate_function_definitions(self, env, code): + self.manager.generate_function_definitions(env, code) + self.body.generate_function_definitions(env, code) + def generate_execution_code(self, code): code.putln("/*with:*/ {") self.manager.generate_evaluation_code(code) diff --git a/tests/run/withstat_py.py b/tests/run/withstat_py.py index 3df6ad63..8345b597 100644 --- a/tests/run/withstat_py.py +++ b/tests/run/withstat_py.py @@ -113,6 +113,26 @@ def with_exception(exit_ret): except: print("outer except") +def functions_in_with(): + """ + >>> f = functions_in_with() + enter + exit + outer except + >>> f(1)[0] + 1 + >>> print(f(1)[1]) + value + """ + try: + with ContextManager("value") as value: + def f(x): return x, value + make = lambda x:x() + raise make(MyException) + except: + print("outer except") + return f + def multitarget(): """ >>> multitarget()