rope / rope / contrib /

The trunk branch has multiple heads

Diff from to

File rope/contrib/

 def code_assist(project, source_code, offset, resource=None,
-                templates=None, maxfixes=1, later_locals=True):
+                templates=None, maxfixes=1, later_locals=True, noerror=False):
     """Return python code completions as a list of `CodeAssistProposal`\s
     `resource` is a `rope.base.resources.Resource` object.  If
     `maxfixes` is the maximum number of errors to fix if the code has
     errors in it.
+    If `noerror` is True empty result is returned when the errors
+    in the code cannot be fixed with `maxfixes` tries.
     If `later_locals` is `False` names defined in this scope and after
     this line is ignored.
                       DeprecationWarning, stacklevel=2)
     assist = _PythonCodeAssist(
         project, source_code, offset, resource=resource,
-        maxfixes=maxfixes, later_locals=later_locals)
+        maxfixes=maxfixes, later_locals=later_locals, noerror=noerror)
     return assist()
 class _PythonCodeAssist(object):
     def __init__(self, project, source_code, offset, resource=None,
-                 maxfixes=1, later_locals=True):
+                 maxfixes=1, later_locals=True, noerror=False):
         self.project = project
         self.pycore = self.project.pycore
         self.code = source_code
         self.resource = resource
         self.maxfixes = maxfixes
         self.later_locals = later_locals
+        self.noerror = noerror
         self.word_finder = worder.Worder(source_code, True)
         self.expression, self.starting, self.offset = \
     def __call__(self):
         if self.offset > len(self.code):
             return []
-        completions = list(self._code_completions().values())
+        try:
+            completions = list(self._code_completions().values())
+        except exceptions.ModuleSyntaxError as err:
+            if self.noerror:
+                return []
+            else:
+                raise err
         if self.expression.strip() == '' and self.starting.strip() != '':
         return completions