forked from VimPlug/jedi
use expression_list instead of commands or call_list
This commit is contained in:
@@ -30,7 +30,7 @@ To *visualize* this (simplified):
|
||||
- ``eval_statement`` - ``<Statement: datetime.date>``
|
||||
|
||||
- Unpacking of the statement into ``[[<Call: datetime.date>]]``
|
||||
- ``follow_call_list``, calls ``eval_call`` with ``<Call: datetime.date>``
|
||||
- ``eval_expression_list``, calls ``eval_call`` with ``<Call: datetime.date>``
|
||||
- ``eval_call`` - searches the ``datetime`` name within the module.
|
||||
|
||||
This is exactly where it starts to get complicated. Now recursions start to
|
||||
@@ -264,7 +264,7 @@ class Evaluator(object):
|
||||
if not r.is_generated:
|
||||
res_new += dynamic.search_params(self, r)
|
||||
if not res_new:
|
||||
c = r.get_commands()[0]
|
||||
c = r.expression_list()[0]
|
||||
if c in ('*', '**'):
|
||||
t = 'tuple' if c == '*' else 'dict'
|
||||
res_new = [er.Instance(
|
||||
@@ -312,7 +312,7 @@ class Evaluator(object):
|
||||
return []
|
||||
result = get_iterator_types(self.eval_statement(loop.inputs[0]))
|
||||
if len(loop.set_vars) > 1:
|
||||
commands = loop.set_stmt.get_commands()
|
||||
commands = loop.set_stmt.expression_list()
|
||||
# loops with loop.set_vars > 0 only have one command
|
||||
result = assign_tuples(commands[0], result, name_str)
|
||||
return result
|
||||
@@ -489,9 +489,9 @@ class Evaluator(object):
|
||||
:param seek_name: A string.
|
||||
"""
|
||||
debug.dbg('eval_statement %s (%s)' % (stmt, seek_name))
|
||||
commands = stmt.get_commands()
|
||||
expression_list = stmt.expression_list()
|
||||
|
||||
result = self.follow_call_list(commands)
|
||||
result = self.eval_expression_list(expression_list)
|
||||
|
||||
# Assignment checking is only important if the statement defines multiple
|
||||
# variables.
|
||||
@@ -503,9 +503,9 @@ class Evaluator(object):
|
||||
return set(result)
|
||||
|
||||
@common.rethrow_uncaught
|
||||
def follow_call_list(self, call_list, follow_array=False):
|
||||
def eval_expression_list(self, expression_list, follow_array=False):
|
||||
"""
|
||||
`call_list` can be either `pr.Array` or `list of list`.
|
||||
`expression_list` can be either `pr.Array` or `list of list`.
|
||||
It is used to evaluate a two dimensional object, that has calls, arrays and
|
||||
operators in it.
|
||||
"""
|
||||
@@ -525,9 +525,9 @@ class Evaluator(object):
|
||||
loop = evaluate_list_comprehension(nested_lc, loop)
|
||||
return loop
|
||||
|
||||
debug.dbg('follow_call_list: %s' % call_list)
|
||||
debug.dbg('eval_expression_list: %s' % expression_list)
|
||||
result = []
|
||||
calls_iterator = iter(call_list)
|
||||
calls_iterator = iter(expression_list)
|
||||
for call in calls_iterator:
|
||||
if pr.Array.is_type(call, pr.Array.NOARRAY):
|
||||
r = list(itertools.chain.from_iterable(self.eval_statement(s)
|
||||
@@ -630,7 +630,7 @@ class Evaluator(object):
|
||||
foo.bar.baz
|
||||
|
||||
`follow_path` is only responsible for completing `.bar.baz`, the rest is
|
||||
done in the `eval_call` function.
|
||||
done in the `follow_call` function.
|
||||
"""
|
||||
# current is either an Array or a Scope.
|
||||
try:
|
||||
@@ -669,7 +669,7 @@ class Evaluator(object):
|
||||
|
||||
def goto(self, stmt, call_path=None):
|
||||
if call_path is None:
|
||||
commands = stmt.get_commands()
|
||||
commands = stmt.expression_list()
|
||||
if len(commands) == 0:
|
||||
return [], ''
|
||||
# Only the first command is important, the rest should basically not
|
||||
@@ -793,7 +793,7 @@ def assign_tuples(tup, results, seek_name):
|
||||
for i, stmt in enumerate(tup):
|
||||
# Used in assignments. There is just one call and no other things,
|
||||
# therefore we can just assume, that the first part is important.
|
||||
command = stmt.get_commands()[0]
|
||||
command = stmt.expression_list()[0]
|
||||
|
||||
if tup.type == pr.Array.NOARRAY:
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ def search_params(evaluator, param):
|
||||
# first assignment details, others would be a syntax error
|
||||
commands, op = param.assignment_details[0]
|
||||
else:
|
||||
commands = param.get_commands()
|
||||
commands = param.expression_list()
|
||||
offset = 1 if commands[0] in ['*', '**'] else 0
|
||||
param_name = str(commands[offset].name)
|
||||
|
||||
@@ -257,7 +257,7 @@ def _scan_statement(stmt, search_name, assignment_details=False):
|
||||
result += _scan_statement(stmt, search_name)
|
||||
return result
|
||||
|
||||
check = list(stmt.get_commands())
|
||||
check = list(stmt.expression_list())
|
||||
if assignment_details:
|
||||
for commands, op in stmt.assignment_details:
|
||||
check += commands
|
||||
@@ -465,7 +465,7 @@ def check_flow_information(evaluator, flow, search_name, pos):
|
||||
def _check_isinstance_type(evaluator, stmt, search_name):
|
||||
from jedi.evaluate import representation as er
|
||||
try:
|
||||
commands = stmt.get_commands()
|
||||
commands = stmt.expression_list()
|
||||
# this might be removed if we analyze and, etc
|
||||
assert len(commands) == 1
|
||||
call = commands[0]
|
||||
@@ -475,7 +475,7 @@ def _check_isinstance_type(evaluator, stmt, search_name):
|
||||
# isinstance check
|
||||
isinst = call.execution.values
|
||||
assert len(isinst) == 2 # has two params
|
||||
obj, classes = [statement.get_commands() for statement in isinst]
|
||||
obj, classes = [statement.expression_list() for statement in isinst]
|
||||
assert len(obj) == 1
|
||||
assert len(classes) == 1
|
||||
assert isinstance(obj[0], pr.Call)
|
||||
|
||||
@@ -227,11 +227,11 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
return self
|
||||
return func
|
||||
|
||||
def get_commands(self):
|
||||
def expression_list(self):
|
||||
# Copy and modify the array.
|
||||
return [InstanceElement(self.instance._evaluator, self.instance, command, self.is_class_var)
|
||||
if not isinstance(command, unicode) else command
|
||||
for command in self.var.get_commands()]
|
||||
for command in self.var.expression_list()]
|
||||
|
||||
def __iter__(self):
|
||||
for el in self.var.__iter__():
|
||||
@@ -545,12 +545,12 @@ class Execution(Executable):
|
||||
key_stmts = []
|
||||
for key in keys:
|
||||
stmt = pr.Statement(self._sub_module, [], start_pos, None)
|
||||
stmt._commands = [key]
|
||||
stmt._expression_list = [key]
|
||||
key_stmts.append(stmt)
|
||||
arr.keys = key_stmts
|
||||
arr.type = array_type
|
||||
|
||||
new_param._commands = [arr]
|
||||
new_param._expression_list = [arr]
|
||||
|
||||
name = copy.copy(param.get_name())
|
||||
name.parent = new_param
|
||||
@@ -594,7 +594,7 @@ class Execution(Executable):
|
||||
values=[value]))
|
||||
key, value = next(var_arg_iterator, (None, None))
|
||||
|
||||
commands = param.get_commands()
|
||||
commands = param.expression_list()
|
||||
keys = []
|
||||
values = []
|
||||
array_type = None
|
||||
@@ -660,14 +660,14 @@ class Execution(Executable):
|
||||
# generate a statement if it's not already one.
|
||||
module = builtin.Builtin.scope
|
||||
stmt = pr.Statement(module, [], (0, 0), None)
|
||||
stmt._commands = [old]
|
||||
stmt._expression_list = [old]
|
||||
|
||||
# *args
|
||||
commands = stmt.get_commands()
|
||||
commands = stmt.expression_list()
|
||||
if not len(commands):
|
||||
continue
|
||||
if commands[0] == '*':
|
||||
arrays = self._evaluator.follow_call_list(commands[1:])
|
||||
arrays = self._evaluator.eval_expression_list(commands[1:])
|
||||
# *args must be some sort of an array, otherwise -> ignore
|
||||
|
||||
for array in arrays:
|
||||
@@ -679,12 +679,12 @@ class Execution(Executable):
|
||||
yield None, helpers.FakeStatement(field_stmt)
|
||||
# **kwargs
|
||||
elif commands[0] == '**':
|
||||
arrays = self._evaluator.follow_call_list(commands[1:])
|
||||
arrays = self._evaluator.eval_expression_list(commands[1:])
|
||||
for array in arrays:
|
||||
if isinstance(array, Array):
|
||||
for key_stmt, value_stmt in array.items():
|
||||
# first index, is the key if syntactically correct
|
||||
call = key_stmt.get_commands()[0]
|
||||
call = key_stmt.expression_list()[0]
|
||||
if isinstance(call, pr.Name):
|
||||
yield call, value_stmt
|
||||
elif isinstance(call, pr.Call):
|
||||
@@ -839,7 +839,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base, Iterable)):
|
||||
def get_index_types(self, index_arr=None):
|
||||
""" Get the types of a specific index or all, if not given """
|
||||
if index_arr is not None:
|
||||
if index_arr and [x for x in index_arr if ':' in x.get_commands()]:
|
||||
if index_arr and [x for x in index_arr if ':' in x.expression_list()]:
|
||||
# array slicing
|
||||
return [self]
|
||||
|
||||
@@ -868,7 +868,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base, Iterable)):
|
||||
index = None
|
||||
for i, key_statement in enumerate(self._array.keys):
|
||||
# Because we only want the key to be a string.
|
||||
key_commands = key_statement.get_commands()
|
||||
key_commands = key_statement.expression_list()
|
||||
if len(key_commands) != 1: # cannot deal with complex strings
|
||||
continue
|
||||
key = key_commands[0]
|
||||
|
||||
Reference in New Issue
Block a user