Anonymous avatar Anonymous committed 3ff4992

syntaxfixer should not return pymodule with empty source_code on syntax errors
original patch by Darren Hoo

Comments (0)

Files changed (3)


             result = PyModule(self.pycore, resource=resource,
+            if result.has_errors:
+                return result
         self.module_map[resource] = result
         return result


                  resource=None, force_errors=False):
         ignore = pycore.project.prefs.get('ignore_syntax_errors', False)
         syntax_errors = force_errors or not ignore
+        self.has_errors = False
             source, node = self._init_source(pycore, source, resource)
         except exceptions.ModuleSyntaxError:
+            self.has_errors = True
             if syntax_errors:


         mod1.write('class A(object):\n    def func2(self):\n        pass\n')
         self.assertTrue('func2' in b_class)
+    def test_caching_pymodule_with_syntax_errors(self):
+        self.project.prefs['ignore_syntax_errors'] = True
+        self.project.prefs['automatic_soa'] = True
+        self.project.pycore._init_automatic_soa()
+        source = 'import sys\nab cd'
+        mod = testutils.create_module(self.project, 'mod')
+        mod.write(source)
+        from rope.contrib import fixsyntax
+        fixer = fixsyntax.FixSyntax(self.project.pycore, source, mod, 10)
+        pymodule = fixer.get_pymodule()
+        self.assertTrue(pymodule.source_code.startswith('import sys\npass\n'))
 class TextChangeDetectorTest(unittest.TestCase):
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
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.