forked from VimPlug/jedi
added tests
This commit is contained in:
15
evaluate.py
15
evaluate.py
@@ -141,7 +141,7 @@ class Execution(Exec):
|
|||||||
calls = parsing.Array(parsing.Array.EMPTY,
|
calls = parsing.Array(parsing.Array.EMPTY,
|
||||||
self.params.parent_stmt)
|
self.params.parent_stmt)
|
||||||
calls.values = [value]
|
calls.values = [value]
|
||||||
new_param.assignment_calls = calls
|
new_param._assignment_calls = calls
|
||||||
name = copy.copy(param.get_name())
|
name = copy.copy(param.get_name())
|
||||||
name.parent = new_param
|
name.parent = new_param
|
||||||
result.append(name)
|
result.append(name)
|
||||||
@@ -323,8 +323,17 @@ def follow_statement(stmt, scope=None):
|
|||||||
scope = stmt.get_parent_until(parsing.Function, Execution,
|
scope = stmt.get_parent_until(parsing.Function, Execution,
|
||||||
parsing.Class, Instance)
|
parsing.Class, Instance)
|
||||||
call_list = stmt.get_assignment_calls()
|
call_list = stmt.get_assignment_calls()
|
||||||
debug.dbg('calls', call_list, call_list.values)
|
debug.dbg('calls', call_list, call_list)
|
||||||
return set(follow_call_list(scope, 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):
|
def follow_call_list(scope, call_list):
|
||||||
|
|||||||
@@ -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;
|
1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request;
|
||||||
abc = [1,2+3]; abc[0].
|
abc = [1,2+3]; abc[0].
|
||||||
import pylab; def add(a1,b1): nana = 1; return a1+b1
|
import pylab; def add(a1,b1): nana = 1; return a1+b1
|
||||||
flow_test.
|
flow_test.; a12, b12 = (1,""); a12.
|
||||||
|
|||||||
36
parsing.py
36
parsing.py
@@ -521,7 +521,8 @@ class Statement(Simple):
|
|||||||
s.parent = self
|
s.parent = self
|
||||||
|
|
||||||
# cache
|
# cache
|
||||||
self.assignment_calls = None
|
self._assignment_calls = None
|
||||||
|
self._assignment_details = None
|
||||||
|
|
||||||
def get_code(self, new_line=True):
|
def get_code(self, new_line=True):
|
||||||
if new_line:
|
if new_line:
|
||||||
@@ -533,6 +534,15 @@ class Statement(Simple):
|
|||||||
""" Get the names for the statement. """
|
""" Get the names for the statement. """
|
||||||
return list(self.set_vars)
|
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):
|
def get_assignment_calls(self):
|
||||||
"""
|
"""
|
||||||
This is not done in the main parser, because it might be slow and
|
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
|
This is not really nice written, sorry for that. If you plan to replace
|
||||||
it and make it nicer, that would be cool :-)
|
it and make it nicer, that would be cool :-)
|
||||||
"""
|
"""
|
||||||
if self.assignment_calls:
|
if self._assignment_calls:
|
||||||
return self.assignment_calls
|
return self._assignment_calls
|
||||||
|
self._assignment_details = []
|
||||||
result = Array(Array.EMPTY, self)
|
result = Array(Array.EMPTY, self)
|
||||||
top = result
|
top = result
|
||||||
level = 0
|
level = 0
|
||||||
@@ -556,25 +567,24 @@ class Statement(Simple):
|
|||||||
#print 'tok', tok_temp, result
|
#print 'tok', tok_temp, result
|
||||||
try:
|
try:
|
||||||
token_type, tok, indent = tok_temp
|
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 \
|
if tok in ['return', 'yield'] or level == 0 and \
|
||||||
'=' in tok and not tok in ['>=', '<=', '==', '!=']:
|
'=' in tok and not tok in ['>=', '<=', '==', '!=']:
|
||||||
# This means, there is an assignment here.
|
# This means, there is an assignment here.
|
||||||
# TODO there may be multiple assignments: a = b = 1
|
# TODO there may be multiple assignments: a = b = 1
|
||||||
|
|
||||||
|
self._assignment_details.append((tok, top))
|
||||||
# initialize the first item
|
# initialize the first item
|
||||||
result = Array(Array.EMPTY, self)
|
result = Array(Array.EMPTY, self)
|
||||||
top = result
|
top = result
|
||||||
continue
|
continue
|
||||||
elif tok == 'as':
|
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)
|
next(tok_iter)
|
||||||
continue
|
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}
|
brackets = {'(': Array.EMPTY, '[': Array.LIST, '{': Array.SET}
|
||||||
is_call = lambda: result.__class__ == Call
|
is_call = lambda: result.__class__ == Call
|
||||||
@@ -653,7 +663,7 @@ class Statement(Simple):
|
|||||||
raise ParserError("Brackets don't match: %s. This is not normal "
|
raise ParserError("Brackets don't match: %s. This is not normal "
|
||||||
"behaviour. Please submit a bug" % level)
|
"behaviour. Please submit a bug" % level)
|
||||||
|
|
||||||
self.assignment_calls = top
|
self._assignment_calls = top
|
||||||
return top
|
return top
|
||||||
|
|
||||||
|
|
||||||
@@ -808,8 +818,8 @@ class Array(Call):
|
|||||||
temp = 'dict'
|
temp = 'dict'
|
||||||
elif self.type == self.SET:
|
elif self.type == self.SET:
|
||||||
temp = 'set'
|
temp = 'set'
|
||||||
return "<%s: %s of %s>" % \
|
parent_str = " of %s" % self.parent if self.parent else ""
|
||||||
(self.__class__.__name__, temp, self.parent)
|
return "<%s: %s%s>" % (self.__class__.__name__, temp, parent_str)
|
||||||
|
|
||||||
|
|
||||||
class NamePart(str):
|
class NamePart(str):
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
a1, b1 = (1, "")
|
||||||
|
#? ['real']
|
||||||
|
a1.real
|
||||||
|
#? ['lower']
|
||||||
|
a1.lower
|
||||||
|
|
||||||
for a in [1,2]:
|
for a in [1,2]:
|
||||||
#? ['real']
|
#? ['real']
|
||||||
@@ -12,3 +17,11 @@ with open('') as f1, open('') as f2:
|
|||||||
f1.closed
|
f1.closed
|
||||||
#? ['closed']
|
#? ['closed']
|
||||||
f2.closed
|
f2.closed
|
||||||
|
|
||||||
|
|
||||||
|
def global_define():
|
||||||
|
#global glob
|
||||||
|
glob = 3
|
||||||
|
|
||||||
|
#? ['real']
|
||||||
|
glob.real
|
||||||
|
|||||||
@@ -5,14 +5,15 @@ class TestClass(object):
|
|||||||
def __init__(self2, a):
|
def __init__(self2, a):
|
||||||
self2.var_inst = a
|
self2.var_inst = a
|
||||||
|
|
||||||
|
def values(self):
|
||||||
|
self.var_local = 3
|
||||||
|
#? ['var_class', 'var_inst', 'var_local']
|
||||||
|
self.var_
|
||||||
|
|
||||||
inst = TestClass(1)
|
inst = TestClass(1)
|
||||||
|
|
||||||
#? ['var_class', 'var_inst']
|
#? ['var_class', 'var_inst', 'var_local']
|
||||||
inst.var
|
inst.var
|
||||||
|
|
||||||
#? ['var_class']
|
#? ['var_class']
|
||||||
TestClass.var_class
|
TestClass.var_class
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user