Anonymous avatar Anonymous committed 1b88e5b

pycore: handling variables defined in except blocks

Comments (0)

Files changed (2)

rope/base/pyobjectsdef.py

                 node.name, type_node, lineno=node.lineno,
                 module=self.get_module(), eval_type=True)
             self.names.update(pynames)
+        for child in node.body:
+            ast.walk(child, self)
 
     def _Import(self, node):
         for import_pair in node.names:

ropetest/pycoretest.py

         c_class = pymod['C'].get_object()
         self.assertFalse('my_var' in c_class)
 
+    def test_variables_defined_in_excepts(self):
+        mod = testutils.create_module(self.project, 'mod')
+        mod.write('try:\n    myvar1 = 1\nexcept:\n    myvar2 = 1\n'
+                  'finally:\n    myvar3 = 1\n')
+        pymod = self.pycore.resource_to_pyobject(mod)
+        self.assertTrue('myvar1' in pymod)
+        self.assertTrue('myvar2' in pymod)
+        self.assertTrue('myvar3' in pymod)
+
     def test_not_leaking_tuple_assigned_names_inside_parent_scope(self):
         mod = testutils.create_module(self.project, 'mod')
         mod.write('class C(object):\n    def f(self):\n'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.