diff --git a/evaluate.py b/evaluate.py index 1e6e155e..de4acb4b 100644 --- a/evaluate.py +++ b/evaluate.py @@ -4,12 +4,15 @@ follow_statement -> follow_call -> follow_paths -> follow_path `get_names_for_scope` and `get_scopes_for_name` are search functions -TODO nonlocal statement TODO doc TODO list comprehensions, priority? -TODO annotations ? how ? type evaluation and return? TODO evaluate asserts (type safety) TODO generators + +python 3 stuff: +TODO class decorators +TODO annotations ? how ? type evaluation and return? +TODO nonlocal statement """ from _compatibility import next @@ -446,13 +449,21 @@ class Array(object): def get_index_types(self, index=None): values = self._array.values if index is not None: - # This is indexing only one element, with a fixed index number, - # otherwise it just ignores the index (e.g. [1+1]) - i = index.get_only_subelement().name - try: - return self.get_exact_index_types(i) - except (IndexError, KeyError): - pass + if [x for x in index if ':' in x]: + return [self] + else: + # This is indexing only one element, with a fixed index number, + # otherwise it just ignores the index (e.g. [1+1]) + try: + # multiple elements in the array + i = index.get_only_subelement().name + except AttributeError: + pass + else: + try: + return self.get_exact_index_types(i) + except (IndexError, KeyError): + pass return self.follow_values(values) def get_exact_index_types(self, index): @@ -841,6 +852,7 @@ def follow_path(path, scope, position=None): if isinstance(current, parsing.Array): # this must be an execution, either () or [] if current.type == parsing.Array.LIST: + print 'cur', current, scope result = scope.get_index_types(current) elif current.type not in [parsing.Array.DICT]: # scope must be a class or func - make an instance or execution diff --git a/parsing.py b/parsing.py index 3a396627..7ef8394a 100644 --- a/parsing.py +++ b/parsing.py @@ -658,7 +658,10 @@ class Statement(Simple): if is_call_or_close(): result = result.parent close_brackets = False - result.add_dictionary_key() + if result.type == Array.LIST: # [:] lookups + result.add_to_current_field(tok) + else: + result.add_dictionary_key() elif tok == '.': if close_brackets and result.parent != top: # only get out of the array, if it is a array execution diff --git a/test/completion/arrays.py b/test/completion/arrays.py index 84ed601b..fa360633 100644 --- a/test/completion/arrays.py +++ b/test/completion/arrays.py @@ -12,7 +12,21 @@ a = list() [a][0].append #? ['append'] -[[a]][0][100].append +[[a,a,a]][2][100].append + +c = [[a,""]] +#? [] +c[0][1].append +#? ['upper'] +c[0][1].upper + +b = [6,7] + +#? ['real'] +b[8-7].real + +#? ['append'] +b[8:].append # -----------------