diff --git a/evaluate.py b/evaluate.py index e3c37bda..38d2b8a0 100644 --- a/evaluate.py +++ b/evaluate.py @@ -141,7 +141,7 @@ class Execution(Exec): calls = parsing.Array(parsing.Array.EMPTY, self.params.parent_stmt) calls.values = [value] - new_param.assignment_calls = calls + new_param._assignment_calls = calls name = copy.copy(param.get_name()) name.parent = new_param result.append(name) @@ -323,8 +323,17 @@ def follow_statement(stmt, scope=None): scope = stmt.get_parent_until(parsing.Function, Execution, parsing.Class, Instance) call_list = stmt.get_assignment_calls() - debug.dbg('calls', call_list, call_list.values) - return set(follow_call_list(scope, call_list)) + debug.dbg('calls', call_list, call_list) + result = set(follow_call_list(scope, call_list)) + + if stmt.assignment_details: + new_result = [] + for op, set_vars in stmt.assignment_details: + stmt.assignment_details[0] + #print '\n\nlala', op, set_vars.values, call_list.values + #print stmt, scope + #result = new_result + return result def follow_call_list(scope, call_list): diff --git a/parsetest.py b/parsetest.py index 412dabe2..9c34138f 100644 --- a/parsetest.py +++ b/parsetest.py @@ -147,4 +147,4 @@ c = b().c3(); abc = datetime; return [abc][0]. ;pylab.; add(1+2,2).; for fi in [ 1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request; abc = [1,2+3]; abc[0]. import pylab; def add(a1,b1): nana = 1; return a1+b1 -flow_test. +flow_test.; a12, b12 = (1,""); a12. diff --git a/parsing.py b/parsing.py index c8ff3a12..60b598b9 100644 --- a/parsing.py +++ b/parsing.py @@ -521,7 +521,8 @@ class Statement(Simple): s.parent = self # cache - self.assignment_calls = None + self._assignment_calls = None + self._assignment_details = None def get_code(self, new_line=True): if new_line: @@ -533,6 +534,15 @@ class Statement(Simple): """ Get the names for the statement. """ return list(self.set_vars) + @property + def assignment_details(self): + if self._assignment_details is None: + # normally, this calls sets this variable + self.get_assignment_calls() + # it may not have been set by get_assignment_calls -> just use an empty + # array + return self._assignment_details or [] + def get_assignment_calls(self): """ This is not done in the main parser, because it might be slow and @@ -542,8 +552,9 @@ class Statement(Simple): This is not really nice written, sorry for that. If you plan to replace it and make it nicer, that would be cool :-) """ - if self.assignment_calls: - return self.assignment_calls + if self._assignment_calls: + return self._assignment_calls + self._assignment_details = [] result = Array(Array.EMPTY, self) top = result level = 0 @@ -556,25 +567,24 @@ class Statement(Simple): #print 'tok', tok_temp, result try: token_type, tok, indent = tok_temp + except TypeError: + # the token is a Name, which has already been parsed + tok = tok_temp + token_type = None + else: if tok in ['return', 'yield'] or level == 0 and \ '=' in tok and not tok in ['>=', '<=', '==', '!=']: # This means, there is an assignment here. # TODO there may be multiple assignments: a = b = 1 + self._assignment_details.append((tok, top)) # initialize the first item result = Array(Array.EMPTY, self) top = result continue elif tok == 'as': - # TODO change with parser to allow multiple statements - # This is the name and can be ignored, because set_vars is - # already caring for this. next(tok_iter) continue - except TypeError: - # the token is a Name, which has already been parsed - tok = tok_temp - token_type = None brackets = {'(': Array.EMPTY, '[': Array.LIST, '{': Array.SET} is_call = lambda: result.__class__ == Call @@ -653,7 +663,7 @@ class Statement(Simple): raise ParserError("Brackets don't match: %s. This is not normal " "behaviour. Please submit a bug" % level) - self.assignment_calls = top + self._assignment_calls = top return top @@ -808,8 +818,8 @@ class Array(Call): temp = 'dict' elif self.type == self.SET: temp = 'set' - return "<%s: %s of %s>" % \ - (self.__class__.__name__, temp, self.parent) + parent_str = " of %s" % self.parent if self.parent else "" + return "<%s: %s%s>" % (self.__class__.__name__, temp, parent_str) class NamePart(str): diff --git a/test/completion/basic.py b/test/completion/basic.py index 7e111308..2baebae5 100644 --- a/test/completion/basic.py +++ b/test/completion/basic.py @@ -1,3 +1,8 @@ +a1, b1 = (1, "") +#? ['real'] +a1.real +#? ['lower'] +a1.lower for a in [1,2]: #? ['real'] @@ -12,3 +17,11 @@ with open('') as f1, open('') as f2: f1.closed #? ['closed'] f2.closed + + +def global_define(): + #global glob + glob = 3 + +#? ['real'] +glob.real diff --git a/test/completion/classes.py b/test/completion/classes.py index c94bddd4..9d7d062a 100644 --- a/test/completion/classes.py +++ b/test/completion/classes.py @@ -5,14 +5,15 @@ class TestClass(object): def __init__(self2, a): self2.var_inst = a - + def values(self): + self.var_local = 3 + #? ['var_class', 'var_inst', 'var_local'] + self.var_ inst = TestClass(1) -#? ['var_class', 'var_inst'] +#? ['var_class', 'var_inst', 'var_local'] inst.var #? ['var_class'] TestClass.var_class - -