Anonymous avatar Anonymous committed 5cc1832

Fixed "'NoneType' object has no attribute 'group'" when restructuring
lines of the form:
'string' .....: new_statement

Original patch by shillo@gmail.com

Comments (0)

Files changed (2)

rope/refactor/patchedast.py

         for children in reversed(self.children_stack):
             for child in children:
                 if isinstance(child, ast.stmt):
-                    return self.lines.get_line_start(child.lineno)
+                    return child.col_offset \
+                           + self.lines.get_line_start(child.lineno)
         return len(self.source.source)
 
     _operators = {'And': 'and', 'Or': 'or', 'Add': '+', 'Sub': '-', 'Mult': '*',

ropetest/refactor/restructuretest.py

         self.assertEquals('def f(p):\n    return dup(p)\nx = dup("")\n'
                           'i = 1 * 2\n', self.mod.read())
 
+    def test_statement_after_string_and_column(self):
+        mod_text = 'def f(x):\n  if a == "a": raise Exception("test")\n'
+        self.mod.write(mod_text)
+        refactoring = restructure.Restructure(self.project, '${a}', '${a}')
+        self.project.do(refactoring.get_changes())
+        self.assertEquals(mod_text, self.mod.read())
+
 
 if __name__ == '__main__':
     unittest.main()
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.