diff --git a/jedi/evaluate.py b/jedi/evaluate.py index f7f4b218..59e2d8f1 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -543,7 +543,6 @@ def follow_statement(stmt, seek_name=None): # Assignment checking is only important if the statement defines multiple # variables. - print(seek_name, stmt, stmt.assignment_details) if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details: new_result = [] for ass_commands, op in stmt.assignment_details: diff --git a/jedi/evaluate_representation.py b/jedi/evaluate_representation.py index 1d627b53..d825e09a 100644 --- a/jedi/evaluate_representation.py +++ b/jedi/evaluate_representation.py @@ -795,13 +795,14 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)): result += dynamic.check_array_additions(self) return set(result) - def get_exact_index_types(self, index): + def get_exact_index_types(self, mixed_index): """ Here the index is an int. Raises IndexError/KeyError """ - if self._array.type == pr.Array.DICT: - old_index = index + index = mixed_index + if self.type == pr.Array.DICT: index = None - for i, key_elements in enumerate(self._array.keys): + for i, key_statement in enumerate(self._array.keys): # Because we only want the key to be a string. + key_elements = key_statement.get_commands() if len(key_elements) == 1: try: str_key = key_elements.get_code() @@ -810,12 +811,12 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)): str_key = key_elements[0].name except AttributeError: str_key = None - if old_index == str_key: + if mixed_index == str_key: index = i break if index is None: raise KeyError('No key found in dictionary') - values = [self._array[index]] + values = [self._array.values[index]] return self._follow_values(values) def _follow_values(self, values): diff --git a/jedi/parsing_representation.py b/jedi/parsing_representation.py index d8b4fe16..1308d13a 100644 --- a/jedi/parsing_representation.py +++ b/jedi/parsing_representation.py @@ -822,8 +822,9 @@ class Statement(Simple): level += 1 if level == 0 and tok in closing_brackets \ - or level == 1 and (tok == ',' or is_assignment(tok) - and break_on_assignment): + or level == 1 and (tok == ',' + or maybe_dict and tok == ':' + or is_assignment(tok) and break_on_assignment): break token_list.append(tok_temp) @@ -1038,6 +1039,7 @@ class Array(Call): """Just add a new statement""" statement.parent = self if is_key: + self.type = self.DICT self.keys.append(statement) else: self.values.append(statement) @@ -1059,20 +1061,20 @@ class Array(Call): def __getitem__(self, key): if self.type == self.DICT: - raise NotImplementedError('no dicts allowed, yet') + raise TypeError('no dicts allowed') return self.values[key] def __iter__(self): if self.type == self.DICT: - raise NotImplementedError('no dicts allowed, yet') + raise TypeError('no dicts allowed') return iter(self.values) def get_code(self): - map = {Array.NOARRAY: '%s', - Array.TUPLE: '(%s)', - Array.LIST: '[%s]', - Array.DICT: '{%s}', - Array.SET: '{%s}' + map = {self.NOARRAY: '%s', + self.TUPLE: '(%s)', + self.LIST: '[%s]', + self.DICT: '{%s}', + self.SET: '{%s}' } inner = [] for i, stmt in enumerate(self.values):