fix 'with' statement at module scope by reactivating old temp code for it
authorStefan Behnel <scoder@users.berlios.de>
Sat, 23 Apr 2011 18:27:25 +0000 (20:27 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 23 Apr 2011 18:27:25 +0000 (20:27 +0200)
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/TreeFragment.py
tests/bugs.txt
tests/run/with_statement_module_level_T536.pyx

index f6bf584cd54bba8cd51e2808a99250df992bc2fa..79d6e3690e135c3a361fc92b446f8b98336c8185 100644 (file)
@@ -958,7 +958,7 @@ class WithTransform(CythonTransform, SkipDeclarations):
                 }, pos=node.pos)
 
         # Set except excinfo target to EXCINFO
-        try_except = result.stats[-1].body.stats[-1]
+        try_except = result.body.stats[-1].body.stats[-1]
         try_except.except_clauses[0].excinfo_target = exc_info
 
         return result
index c50f4f9555567cb08390f869621d5b2993b71b58..6ab0bf7085709f9a8b4a77e6fd68d440453a7f6b 100644 (file)
@@ -121,16 +121,15 @@ class TemplateTransform(VisitorTransform):
         temphandles = []
         for temp in temps:
             TemplateTransform.temp_name_counter += 1
-            handle = "__tmpvar_%d" % TemplateTransform.temp_name_counter
-#            handle = UtilNodes.TempHandle(PyrexTypes.py_object_type)
+            handle = UtilNodes.TempHandle(PyrexTypes.py_object_type)
             tempmap[temp] = handle
-#            temphandles.append(handle)
+            temphandles.append(handle)
         self.tempmap = tempmap
         result = super(TemplateTransform, self).__call__(node)
-#        if temps:
-#            result = UtilNodes.TempsBlockNode(self.get_pos(node),
-#                                              temps=temphandles,
-#                                              body=result)
+        if temps:
+            result = UtilNodes.TempsBlockNode(self.get_pos(node),
+                                              temps=temphandles,
+                                              body=result)
         return result
 
     def get_pos(self, node):
@@ -161,9 +160,8 @@ class TemplateTransform(VisitorTransform):
     def visit_NameNode(self, node):
         temphandle = self.tempmap.get(node.name)
         if temphandle:
-            return NameNode(pos=node.pos, name=temphandle)
             # Replace name with temporary
-            #return temphandle.ref(self.get_pos(node))
+            return temphandle.ref(self.get_pos(node))
         else:
             return self.try_substitution(node, node.name)
 
index c6fa8fe916af861c6e32a04c7e01f4dd738b8600..c586868ee99e8a6b4609ac2e72a50519b282391b 100644 (file)
@@ -10,7 +10,6 @@ cfunc_call_tuple_args_T408
 compile.cpp_operators
 cpp_templated_ctypedef
 cpp_structs
-with_statement_module_level_T536
 function_as_method_T494
 closure_inside_cdef_T554
 pure_mode_cmethod_inheritance_T583
index bc163b56fb34f1a8e4766804e8b90138bfced75f..563fb32c6a3b85c7e935a608cf6eaa00e81afd28 100644 (file)
@@ -3,17 +3,32 @@
 __doc__ = """
 >>> inner_result
 ['ENTER']
->>> result
+>>> result  # doctest: +ELLIPSIS
+['ENTER', "EXIT (<type 'exceptions.ValueError'>, ValueError('TEST',), <traceback object at ...)"]
+
+>>> inner_result_no_exc
+['ENTER']
+>>> result_no_exc
 ['ENTER', 'EXIT (None, None, None)']
 """
 
-result = []
-
 class ContextManager(object):
+    def __init__(self, result):
+        self.result = result
     def __enter__(self):
-        result.append("ENTER")
+        self.result.append("ENTER")
     def __exit__(self, *values):
-        result.append("EXIT %r" % (values,))
+        self.result.append("EXIT %r" % (values,))
+        return True
+
+result_no_exc = []
+
+with ContextManager(result_no_exc) as c:
+    inner_result_no_exc = result_no_exc[:]
+
+result = []
 
-with ContextManager() as c:
+with ContextManager(result) as c:
     inner_result = result[:]
+    raise ValueError('TEST')
+