From dafd5e0e29ac340f8f35e7a119b90ba60a2cc002 Mon Sep 17 00:00:00 2001
From: Stefan Behnel <scoder@users.berlios.de>
Date: Mon, 25 Apr 2011 07:34:49 +0200
Subject: [PATCH] fix function declarations inside of 'with' blocks

---
 Cython/Compiler/Nodes.py |  4 ++++
 tests/run/withstat_py.py | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py
index 006133c4d..51ef88f3f 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 3df6ad636..8345b5973 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 <type 'type'> <type 'MyException'> <type 'traceback'>
+    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()
-- 
2.30.9