diff --git a/builtin.py b/builtin.py index 6b2a483f..8a7825dc 100644 --- a/builtin.py +++ b/builtin.py @@ -42,7 +42,7 @@ class Parser(object): name = os.path.basename(self.path) self.name = name.rpartition('.')[0] # cut file type (normally .so) self.path = os.path.dirname(self.path) - print self.name, self.path + #print self.name, self.path self._content = {} self._parser = None self._module = None @@ -54,13 +54,13 @@ class Parser(object): self.sys_path.insert(0, self.path) temp, sys.path = sys.path, self.sys_path - print 'sypa', sys.path + #print 'sypa', sys.path TODO reenable and check (stackoverflow ticket) exec 'import %s as module' % self.name in self._content self.sys_path, sys.path = sys.path, temp self.sys_path.pop(0) self._module = self._content['module'] - print 'mod', self._content['module'] + #print 'mod', self._content['module'] return self._module @property @@ -69,7 +69,7 @@ class Parser(object): if not self._parser: try: timestamp, parser = Parser.cache[self.name, self.path] - if timestamp == os.path.getmtime(self.path): + if not self.path or timestamp == os.path.getmtime(self.path): debug.dbg('hit builtin cache') self._parser = parser else: diff --git a/evaluate.py b/evaluate.py index 4f8281f5..1a25d9f3 100644 --- a/evaluate.py +++ b/evaluate.py @@ -276,7 +276,7 @@ def strip_imports(scopes): result = [] for s in scopes: if isinstance(s, parsing.Import): - print 'dini mueter, steile griech!' + #print 'dini mueter, steile griech!' try: result += follow_import(s) except modules.ModuleNotFound: diff --git a/ftest.py b/ftest.py index 7f44c378..5f4944c3 100755 --- a/ftest.py +++ b/ftest.py @@ -2,7 +2,7 @@ import functions -#functions.debug.debug_function = functions.debug.print_to_stdout +functions.debug.debug_function = functions.debug.print_to_stdout functions.debug.ignored_modules = ['parsing', 'builtin'] functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules'] functions.modules.module_find_path.insert(0, '.') diff --git a/functions.py b/functions.py index 28559fbe..f6d5facb 100644 --- a/functions.py +++ b/functions.py @@ -188,6 +188,7 @@ def complete(source, row, column, source_path): except IndexError: completions = evaluate.get_names_for_scope(scope) else: + stmt.parent = scope scopes = evaluate.follow_statement(stmt, scope) completions = [] diff --git a/parsetest.py b/parsetest.py index 1c3fb8d8..7a47dd91 100644 --- a/parsetest.py +++ b/parsetest.py @@ -147,4 +147,4 @@ c = b().c3() 1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request; abc = [1,2+3]; abc[0]. import pylab -pylab.one +abc = datetime; return [abc][0]. diff --git a/parsing.py b/parsing.py index a3b45020..16128ff2 100644 --- a/parsing.py +++ b/parsing.py @@ -65,7 +65,7 @@ class Simple(object): self.parent = None def get_parent_until(self, *classes): - """ Takes always the parent, until one class """ + """ Takes always the parent, until one class (not a Class) """ scope = self while not (scope.parent is None or scope.__class__ in classes): scope = scope.parent @@ -209,14 +209,14 @@ class Scope(Simple): def __repr__(self): try: name = self.name - except: + except AttributeError: try: name = self.command - except: + except AttributeError: name = self.module_path return "<%s: %s@%s-%s>" % \ - (self.__class__.__name__, name, self.line_nr, self.line_end) + (self.__class__.__name__, name, self.line_nr, self.__hash__()) class GlobalScope(Scope): @@ -242,8 +242,7 @@ class GlobalScope(Scope): # set no parent here, because globals are not defined in this scope. def get_set_vars(self): - n = [] - n += super(GlobalScope, self).get_set_vars() + n = super(GlobalScope, self).get_set_vars() n += self.global_vars return n @@ -321,10 +320,9 @@ class Function(Scope): return str def get_set_vars(self): - n = [] + n = super(Function, self).get_set_vars() for i, p in enumerate(self.params): n += p.set_vars or p.used_vars - n += super(Function, self).get_set_vars() return n @@ -393,8 +391,7 @@ class Flow(Scope): generate the output. """ if is_internal_call: - n = [] - n += self.set_vars + n = list(self.set_vars) if self.statement: n += self.statement.set_vars if self.next: @@ -519,7 +516,7 @@ class Statement(Simple): def get_set_vars(self): """ Get the names for the statement. """ - return self.set_vars + return list(self.set_vars) def get_assignment_calls(self): """ @@ -1148,9 +1145,12 @@ class PyFuzzyParser(object): if is_return: # add returns to the scope func = self.scope.get_parent_until(Function) - func.returns.append(stmt) if is_return == 'yield': func.is_generator = True + try: + func.returns.append(stmt) + except AttributeError: + debug.warning('return in non-function') return stmt, tok diff --git a/test/completion/arrays.py b/test/completion/arrays.py index e8fd3d69..47674740 100644 --- a/test/completion/arrays.py +++ b/test/completion/arrays.py @@ -1,3 +1,7 @@ #? ['imag'] [1,2][0].imag + +a = list() +#? ['append'] +[a][0].append diff --git a/test/run.py b/test/run.py index 5d37c042..9114ca4e 100755 --- a/test/run.py +++ b/test/run.py @@ -49,7 +49,7 @@ def completion_test(source): tests += 1 else: try: - correct = re.search(r'#\?\s*([^\n]+)', line).group(1) + correct = re.search(r'(?:^|\s)#\?\s*([^\n]+)', line).group(1) except: correct = None return tests, fails