fix function declarations inside of 'with' blocks
authorStefan Behnel <scoder@users.berlios.de>
Mon, 25 Apr 2011 05:34:49 +0000 (07:34 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 25 Apr 2011 05:34:49 +0000 (07:34 +0200)
Cython/Compiler/Nodes.py
tests/run/withstat_py.py

index 006133c4d4f05db980490228d7d8bf1ae4eaf5f1..51ef88f3f0be72446ed67045d2afc8d274834a52 100644 (file)
@@ -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)
index 3df6ad6361058c57f0abc522c419f2c5868dcecd..8345b5973507ff463489537bccfbc206fcfe0379 100644 (file)
@@ -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()