forked from VimPlug/jedi
moved the input of get_index_types to a more typical type system
This commit is contained in:
@@ -272,7 +272,8 @@ class Evaluator(object):
|
|||||||
# This must be an execution, either () or [].
|
# This must be an execution, either () or [].
|
||||||
if current.type == pr.Array.LIST:
|
if current.type == pr.Array.LIST:
|
||||||
if hasattr(typ, 'get_index_types'):
|
if hasattr(typ, 'get_index_types'):
|
||||||
result = typ.get_index_types(current)
|
slc = iterable.create_indexes_or_slices(self, current)
|
||||||
|
result = typ.get_index_types(slc)
|
||||||
elif current.type not in [pr.Array.DICT]:
|
elif current.type not in [pr.Array.DICT]:
|
||||||
# Scope must be a class or func - make an instance or execution.
|
# Scope must be a class or func - make an instance or execution.
|
||||||
result = self.execute(typ, current)
|
result = self.execute(typ, current)
|
||||||
|
|||||||
@@ -98,18 +98,16 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
self._evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
self._array = array
|
self._array = array
|
||||||
|
|
||||||
def get_index_types(self, index_arr=None):
|
def get_index_types(self, indexes=[]):
|
||||||
""" Get the types of a specific index or all, if not given """
|
""" Get the types of a specific index or all, if not given """
|
||||||
if index_arr is not None:
|
result = []
|
||||||
if index_arr and [x for x in index_arr if ':' in x.expression_list()]:
|
if [index for index in indexes if isinstance(index, Slice)]:
|
||||||
# array slicing
|
|
||||||
return [self]
|
return [self]
|
||||||
|
|
||||||
index_possibilities = _follow_values(self._evaluator, index_arr)
|
if len(indexes) == 1:
|
||||||
if len(index_possibilities) == 1:
|
|
||||||
# This is indexing only one element, with a fixed index number,
|
# This is indexing only one element, with a fixed index number,
|
||||||
# otherwise it just ignores the index (e.g. [1+1]).
|
# otherwise it just ignores the index (e.g. [1+1]).
|
||||||
index = index_possibilities[0]
|
index = indexes[0]
|
||||||
if isinstance(index, compiled.CompiledObject) \
|
if isinstance(index, compiled.CompiledObject) \
|
||||||
and isinstance(index.obj, (int, str, unicode)):
|
and isinstance(index.obj, (int, str, unicode)):
|
||||||
with common.ignored(KeyError, IndexError, TypeError):
|
with common.ignored(KeyError, IndexError, TypeError):
|
||||||
@@ -418,6 +416,7 @@ def _follow_values(evaluator, values):
|
|||||||
class Slice(object):
|
class Slice(object):
|
||||||
def __init__(self, evaluator, start, stop, step):
|
def __init__(self, evaluator, start, stop, step):
|
||||||
self._evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
|
# all of them are either a Precedence or None.
|
||||||
self._start = start
|
self._start = start
|
||||||
self._stop = stop
|
self._stop = stop
|
||||||
self._step = step
|
self._step = step
|
||||||
@@ -432,16 +431,16 @@ class Slice(object):
|
|||||||
return self._result(self._step)
|
return self._result(self._step)
|
||||||
|
|
||||||
def _result(self, element):
|
def _result(self, element):
|
||||||
return self._evaluator.process_precedence_element()
|
return self._evaluator.process_precedence_element(element)
|
||||||
|
|
||||||
|
|
||||||
def create_index_or_slice(evaluator, index_array):
|
def create_indexes_or_slices(evaluator, index_array):
|
||||||
if not index_array:
|
if not index_array:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# Just take the first part of the "array", because this is Python stdlib
|
# Just take the first part of the "array", because this is Python stdlib
|
||||||
# behavior. Numpy et al. perform differently, but we won't understand that
|
# behavior. Numpy et al. perform differently, but Jedi won't understand
|
||||||
# anyway.
|
# that anyway.
|
||||||
expression_list = index_array[0].expression_list()
|
expression_list = index_array[0].expression_list()
|
||||||
prec = precedence.create_precedence(expression_list)
|
prec = precedence.create_precedence(expression_list)
|
||||||
|
|
||||||
@@ -449,12 +448,12 @@ def create_index_or_slice(evaluator, index_array):
|
|||||||
if isinstance(prec, precedence.Precedence) and prec.operator == ':':
|
if isinstance(prec, precedence.Precedence) and prec.operator == ':':
|
||||||
start = prec.left
|
start = prec.left
|
||||||
if isinstance(start, precedence.Precedence) and start.operator == ':':
|
if isinstance(start, precedence.Precedence) and start.operator == ':':
|
||||||
start = start.left
|
|
||||||
stop = start.right
|
stop = start.right
|
||||||
step = stop.right
|
start = start.left
|
||||||
|
step = prec.right
|
||||||
else:
|
else:
|
||||||
stop = stop.right
|
stop = prec.right
|
||||||
step = None
|
step = None
|
||||||
return Slice(evaluator, start, stop, step)
|
return [Slice(evaluator, start, stop, step)]
|
||||||
else:
|
else:
|
||||||
return _follow_values(evaluator, index_array)
|
return evaluator.process_precedence_element(prec) or []
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from jedi.parser import representation as pr
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.common import PushBackIterator
|
from jedi.common import PushBackIterator
|
||||||
from jedi.evaluate.compiled import CompiledObject, create
|
from jedi.evaluate.compiled import CompiledObject, create
|
||||||
from jedi.evaluate import iterable
|
|
||||||
|
|
||||||
|
|
||||||
class PythonGrammar(object):
|
class PythonGrammar(object):
|
||||||
@@ -197,6 +196,7 @@ def _element_calculate(left, operator, right):
|
|||||||
|
|
||||||
if operator == '*':
|
if operator == '*':
|
||||||
# for iterables, ignore * operations
|
# for iterables, ignore * operations
|
||||||
|
from jedi.evaluate import iterable
|
||||||
if isinstance(left, iterable.Array) or is_string(left):
|
if isinstance(left, iterable.Array) or is_string(left):
|
||||||
return [left]
|
return [left]
|
||||||
elif operator == '+':
|
elif operator == '+':
|
||||||
|
|||||||
@@ -167,10 +167,9 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_index_types(self, index=None):
|
def get_index_types(self, indexes=[]):
|
||||||
args = [] if index is None else [index]
|
|
||||||
try:
|
try:
|
||||||
return self.execute_subscope_by_name('__getitem__', args)
|
return self.execute_subscope_by_name('__getitem__', indexes)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
debug.warning('No __getitem__, cannot access the array.')
|
debug.warning('No __getitem__, cannot access the array.')
|
||||||
return []
|
return []
|
||||||
|
|||||||
Reference in New Issue
Block a user