1
0
forked from VimPlug/jedi

refactor a lot of er.Array

This commit is contained in:
David Halter
2013-02-08 13:09:08 +01:00
parent 39f43c52fe
commit 4f060ddcd9

View File

@@ -775,24 +775,20 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)):
""" Get the types of a specific index or all, if not given """ """ Get the types of a specific index or all, if not given """
# array slicing # array slicing
if index_call_list is not None: if index_call_list is not None:
print index_call_list
if index_call_list and [x for x in index_call_list if ':' in x.token_list]: if index_call_list and [x for x in index_call_list if ':' in x.token_list]:
return [self] return [self]
index_possibilities = [evaluate.follow_statement(i) for i in index_call_list] index_possibilities = self._follow_values(index_call_list)
if len(index_possibilities) == 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]).
try: index = index_possibilities[0]
# Multiple elements in the array are not wanted. var_args if isinstance(index, Instance) \
# and get_only_subelement can raise AttributeErrors. and str(index.name) in ['int', 'str'] \
i = index_possibilities[0].var_args.get_only_subelement() and len(index.var_args) == 1:
except AttributeError:
pass
else:
try: try:
return self.get_exact_index_types(i) return self.get_exact_index_types(index.var_args[0])
except (IndexError, KeyError): except (KeyError, IndexError):
pass pass
result = list(self._follow_values(self._array.values)) result = list(self._follow_values(self._array.values))
@@ -824,8 +820,8 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)):
def _follow_values(self, values): def _follow_values(self, values):
""" helper function for the index getters """ """ helper function for the index getters """
return itertools.chain.from_iterable(evaluate.follow_statement(v) return list(itertools.chain.from_iterable(evaluate.follow_statement(v)
for v in values) for v in values))
def get_defined_names(self): def get_defined_names(self):
""" """