Anonymous avatar Anonymous committed 8e1ebf1

Added a force_errors argument to PyCore.get_string_module()

Comments (0)

Files changed (4)

rope/base/codeanalyze.py

 
 
 def get_block_start(lines, lineno, maximum_indents=80):
-    """Aproximate block start"""
+    """Approximate block start"""
     pattern = get_block_start_patterns()
     for i in range(lineno, 0, -1):
         match = pattern.search(lines.get_line(i))

rope/base/pycore.py

             raise ModuleNotFoundError('Module %s not found' % name)
         return self.resource_to_pyobject(module)
 
-    def get_string_module(self, module_content, resource=None):
-        """Returns a `PyObject` object for the given module_content"""
-        return PyModule(self, module_content, resource)
+    def get_string_module(self, module_content, resource=None,
+                          force_errors=False):
+        """Returns a `PyObject` object for the given module_content
+
+        If `force_errors` is `True`, `exceptions.ModuleSyntaxError` is
+        raised if module has syntax errors.  This overrides
+        ``ignore_syntax_errors`` project config.
+
+        """
+        return PyModule(self, module_content, resource, force_errors=True)
 
     def get_string_scope(self, module_content, resource=None):
         """Returns a `Scope` object for the given module_content"""

rope/base/pyobjects.py

 
 class PyModule(_PyModule):
 
-    def __init__(self, pycore, source_code, resource=None):
+    def __init__(self, pycore, source_code,
+                 resource=None, force_errors=False):
         if isinstance(source_code, unicode):
             source_code = source_code.encode('utf-8')
         self.source_code = source_code
         try:
             ast_node = ast.parse(source_code.rstrip(' \t'))
         except SyntaxError, e:
-            if not pycore.project.prefs.get('ignore_syntax_errors', False):
+            ignore = pycore.project.prefs.get('ignore_syntax_errors', False)
+            if force_errors or not ignore:
                 filename = 'string'
                 if resource:
                     filename = resource.path

rope/contrib/codeassist.py

         lines = commenter.lines
         source_code = '\n'.join(lines)
         module_scope = _get_pymodule(self.pycore, source_code,
-                                    self.resource).get_scope()
+                                     self.resource).get_scope()
         result = {}
-        indents = _get_line_indents(lines[_logical_start(lines, lineno) - 1])
-        inner_scope = module_scope.get_inner_scope_for_line(lineno, indents)
+        start = _logical_start(lines, lineno)
+        indents = _get_line_indents(lines[start - 1])
+        inner_scope = module_scope.get_inner_scope_for_line(start, indents)
         if self.expression.strip() != '':
             result.update(self._get_dotted_completions(module_scope,
                                                        inner_scope))
         stop = lines.get_line_start(stop_line)
         if word_finder.is_on_function_call_keyword(offset - 1, stop):
             name_finder = ScopeNameFinder(pymodule)
-            function_parens = word_finder.find_parens_start_from_inside(offset - 1, stop)
+            function_parens = word_finder.\
+                find_parens_start_from_inside(offset - 1, stop)
             primary = word_finder.get_primary_at(function_parens - 1)
             try:
-                function_pyname = ScopeNameFinder.get_pyname_in_scope(scope,
-                                                                      primary)
+                function_pyname = ScopeNameFinder.\
+                    get_pyname_in_scope(scope, primary)
             except BadIdentifierError, e:
                 return {}
             if function_pyname is not None:
 def _get_pymodule(pycore, source_code, resource):
     if resource and resource.exists() and source_code == resource.read():
         return pycore.resource_to_pyobject(resource)
-    return pycore.get_string_module(source_code, resource=resource)
-
+    return pycore.get_string_module(source_code, resource=resource,
+                                    force_errors=True)
 
 def _get_line_indents(line):
     return rope.base.codeanalyze.count_line_indents(line)
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.