Commits

Anonymous committed cc59e86

pycore: with statements with no optional vars

  • Participants
  • Parent commits fd95f93

Comments (0)

Files changed (2)

rope/base/pyobjectsdef.py

             ast.walk(child, self)
 
     def _With(self, node):
-        # ???: What if there are no optional vars?
-        names = rope.base.evaluate._get_evaluated_names(
-            node.optional_vars, node.context_expr, evaluation='.__enter__()',
-            lineno=node.lineno, module=self.get_module())
-        self.names.update(names)
+        if node.optional_vars:
+            names = rope.base.evaluate._get_evaluated_names(
+                node.optional_vars, node.context_expr, lineno=node.lineno,
+                evaluation='.__enter__()', module=self.get_module())
+            self.names.update(names)
         for child in node.body:
             ast.walk(child, self)
 

ropetest/pycoretest.py

         var = pymod['var'].get_object()
         self.assertEquals(a_class, var.get_type())
 
+    @testutils.run_only_for_25
+    def test_with_statement_with_no_vars(self):
+        code = 'with open("file"):    pass\n'
+        if sys.version_info < (2, 6, 0):
+            code = 'from __future__ import with_statement\n' + code
+        pymod = self.pycore.get_string_module(code)
+        pymod.get_attributes()
+
     def test_check_for_else_block(self):
         mod = self.pycore.get_string_module('for i in range(10):\n    pass\n'
                                             'else:\n    myvar = 1\n')