diff --git a/_compatibility.py b/_compatibility.py index 5cb8adc8..a7d52d1b 100644 --- a/_compatibility.py +++ b/_compatibility.py @@ -8,11 +8,12 @@ try: next = next except NameError: _raiseStopIteration = object() + def next(iterator, default=_raiseStopIteration): if not hasattr(iterator, 'next'): - raise TypeError("not an iterator") + raise TypeError("not an iterator") try: - return iterator.next() + return iterator.next() except StopIteration: if default is _raiseStopIteration: raise diff --git a/builtin.py b/builtin.py index 229b3faf..0c6735fd 100644 --- a/builtin.py +++ b/builtin.py @@ -36,10 +36,6 @@ class CachedModule(object): def _load_module(self): source = self._get_source() self._parser = parsing.PyFuzzyParser(source, self.path or self.name) - #except: - # debug.warning('not possible to resolve', self.name, source) - #open('builtin_fail', 'w').write(code) - # raise p_time = None if not self.path else os.path.getmtime(self.path) self.cache[self.path or self.name] = p_time, self._parser @@ -163,10 +159,10 @@ class Parser(CachedModule): try: try: path = scope.__file__ - except: + except AttributeError: path = '?' code += '# Generated module %s from %s\n' % (scope.__name__, path) - except: + except AttributeError: pass code += '"""\n%s\n"""\n' % scope.__doc__ @@ -189,7 +185,7 @@ class Parser(CachedModule): doc_str = parsing.indent_block('"""\n%s\n"""\n' % func.__doc__) try: mixin = self.mixin_funcs[name] - except: + except KeyError: # normal code generation code += 'def %s(%s):\n' % (name, params) code += doc_str diff --git a/evaluate.py b/evaluate.py index a316c42d..85959256 100644 --- a/evaluate.py +++ b/evaluate.py @@ -251,7 +251,7 @@ class Instance(Executable): """ try: return func.params[0].used_vars[0].names[0] - except: + except IndexError: return None def get_defined_names(self): @@ -414,7 +414,7 @@ class Execution(Executable): Get the return vars of a function. """ stmts = [] - #print '\n\n', self.var_args, self.var_args.values, self.var_args.parent_stmt + #a = self.var_args; print '\n\n', a, a.values, a.parent_stmt if isinstance(self.base, Class): # there maybe executions of executions stmts = [Instance(self.base, self.var_args)] @@ -442,8 +442,8 @@ class Execution(Executable): # TODO how can we deactivate this again? #self.base.param_cb = None - # func could have changed because of decorators, so clear them - # again + # func could have changed because of decorators, so clear + # them again self.base.is_decorated = False else: debug.warning("no execution possible", func) @@ -488,6 +488,7 @@ class Generator(object): def __repr__(self): return "<%s of %s>" % (self.__class__.__name__, self.func) + class Array(object): """ Used as a mirror to parsing.Array, if needed. It defines some getter diff --git a/functions.py b/functions.py index 8a726427..18aa9009 100644 --- a/functions.py +++ b/functions.py @@ -85,7 +85,7 @@ class Definition(object): path = str(par.path) try: - return path[path.rindex('/')+1:] + return path[path.rindex('/') + 1:] except ValueError: return path @@ -107,6 +107,7 @@ class Definition(object): def __repr__(self): return "<%s %s>" % (self.__class__.__name__, self) + def get_completion_parts(path): """ Returns the parts for the completion @@ -133,7 +134,8 @@ def complete(source, row, column, source_path): :rtype: list """ try: - scopes, path, dot, like = prepare_goto(source, row, column, source_path, True) + scopes, path, dot, like = prepare_goto(source, row, column, + source_path, True) except NotFoundError: # normally this would be used like this: `NotFoundError as exc`, but # this guarantues backwards compatibility with Python2.5. @@ -190,7 +192,7 @@ def prepare_goto(source, row, column, source_path, is_like_search): if is_like_search: stmt.line_nr = row else: - stmt.line_nr = row+1 + stmt.line_nr = row + 1 stmt.indent = column stmt.parent = scope scopes = evaluate.follow_statement(stmt, scope=scope) @@ -200,6 +202,7 @@ def prepare_goto(source, row, column, source_path, is_like_search): else: return scopes + def get_definitions(source, row, column, source_path): """ Returns the definitions of a the path under the cursor.