diff --git a/evaluate.py b/evaluate.py index 87b51d0e..506673ac 100644 --- a/evaluate.py +++ b/evaluate.py @@ -4,14 +4,13 @@ follow_statement -> follow_call -> follow_paths -> follow_path `get_names_for_scope` and `get_scopes_for_name` are search functions -TODO include super classes TODO nonlocal statement TODO doc TODO list comprehensions, priority? -TODO care for *args **kwargs -TODO annotations +TODO annotations ? how ? +TODO generators """ -from _compatibility import next, literal_eval +from _compatibility import next import itertools import copy @@ -403,7 +402,6 @@ class Array(object): # otherwise it just ignores the index (e.g. [1+1]) i = index.get_only_subelement().name try: - print 'index', i return self.get_exact_index_types(i) except (IndexError, KeyError): pass @@ -413,16 +411,19 @@ class Array(object): if self._array.type == parsing.Array.DICT: old_index = index index = None - for key_elements in self._array.keys: + for i, key_elements in enumerate(self._array.keys): # because we only want the key to be a string if len(key_elements) == 1: try: - str_key = key_elements[0].name - if old_index == str_key: - index = str_key.name - break + str_key = key_elements.get_code() except AttributeError: - pass + try: + str_key = key_elements[0].name + except AttributeError: + str_key = None + if old_index == str_key: + index = i + break if index is None: raise KeyError('No key found in dictionary') values = [self._array[index]] diff --git a/parsing.py b/parsing.py index 1bdc1c3e..18b1d756 100644 --- a/parsing.py +++ b/parsing.py @@ -769,8 +769,8 @@ class Call(object): yield y def __repr__(self): - return "<%s: %s of %s>" % \ - (self.__class__.__name__, self.name, self.parent) + return "<%s: %s>" % \ + (self.__class__.__name__, self.name) class Array(Call): @@ -820,6 +820,7 @@ class Array(Call): """ self.type = Array.DICT self.keys.append(self.values.pop()) + self.values.append([]) def get_only_subelement(self): """ diff --git a/test/completion/arrays.py b/test/completion/arrays.py index 2dede46b..84ed601b 100644 --- a/test/completion/arrays.py +++ b/test/completion/arrays.py @@ -124,6 +124,7 @@ dic2 = {'asdf': 3, 'b': 'str'} dic2['asdf'].real #? [] dic2['asdf'].upper +# string literal #? ['real'] dic2[r'asdf'].real #? [] diff --git a/test/completion/functions.py b/test/completion/functions.py index 3a86f505..8d789a3b 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -153,7 +153,7 @@ exe.items def fu(a=1, b="", *args, **kwargs): return a, b, args, kwargs -exe = fu(list, 1, "", c=set) +exe = fu(list, 1, "", c=set, d="") #? ['append'] exe[0].append @@ -167,3 +167,5 @@ exe[2][0].upper exe[3].items #? ['union'] exe[3]['c'].union +#? [] +exe[3]['c'].upper