fixed some dict issues

This commit is contained in:
David Halter
2013-02-08 21:18:58 +01:00
parent a5e9977e94
commit 2fef25b1b1
3 changed files with 18 additions and 16 deletions

View File

@@ -543,7 +543,6 @@ def follow_statement(stmt, seek_name=None):
# Assignment checking is only important if the statement defines multiple # Assignment checking is only important if the statement defines multiple
# variables. # variables.
print(seek_name, stmt, stmt.assignment_details)
if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details: if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details:
new_result = [] new_result = []
for ass_commands, op in stmt.assignment_details: for ass_commands, op in stmt.assignment_details:

View File

@@ -795,13 +795,14 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)):
result += dynamic.check_array_additions(self) result += dynamic.check_array_additions(self)
return set(result) 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 """ """ Here the index is an int. Raises IndexError/KeyError """
if self._array.type == pr.Array.DICT: index = mixed_index
old_index = index if self.type == pr.Array.DICT:
index = None 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. # Because we only want the key to be a string.
key_elements = key_statement.get_commands()
if len(key_elements) == 1: if len(key_elements) == 1:
try: try:
str_key = key_elements.get_code() str_key = key_elements.get_code()
@@ -810,12 +811,12 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)):
str_key = key_elements[0].name str_key = key_elements[0].name
except AttributeError: except AttributeError:
str_key = None str_key = None
if old_index == str_key: if mixed_index == str_key:
index = i index = i
break break
if index is None: if index is None:
raise KeyError('No key found in dictionary') raise KeyError('No key found in dictionary')
values = [self._array[index]] values = [self._array.values[index]]
return self._follow_values(values) return self._follow_values(values)
def _follow_values(self, values): def _follow_values(self, values):

View File

@@ -822,8 +822,9 @@ class Statement(Simple):
level += 1 level += 1
if level == 0 and tok in closing_brackets \ if level == 0 and tok in closing_brackets \
or level == 1 and (tok == ',' or is_assignment(tok) or level == 1 and (tok == ','
and break_on_assignment): or maybe_dict and tok == ':'
or is_assignment(tok) and break_on_assignment):
break break
token_list.append(tok_temp) token_list.append(tok_temp)
@@ -1038,6 +1039,7 @@ class Array(Call):
"""Just add a new statement""" """Just add a new statement"""
statement.parent = self statement.parent = self
if is_key: if is_key:
self.type = self.DICT
self.keys.append(statement) self.keys.append(statement)
else: else:
self.values.append(statement) self.values.append(statement)
@@ -1059,20 +1061,20 @@ class Array(Call):
def __getitem__(self, key): def __getitem__(self, key):
if self.type == self.DICT: if self.type == self.DICT:
raise NotImplementedError('no dicts allowed, yet') raise TypeError('no dicts allowed')
return self.values[key] return self.values[key]
def __iter__(self): def __iter__(self):
if self.type == self.DICT: if self.type == self.DICT:
raise NotImplementedError('no dicts allowed, yet') raise TypeError('no dicts allowed')
return iter(self.values) return iter(self.values)
def get_code(self): def get_code(self):
map = {Array.NOARRAY: '%s', map = {self.NOARRAY: '%s',
Array.TUPLE: '(%s)', self.TUPLE: '(%s)',
Array.LIST: '[%s]', self.LIST: '[%s]',
Array.DICT: '{%s}', self.DICT: '{%s}',
Array.SET: '{%s}' self.SET: '{%s}'
} }
inner = [] inner = []
for i, stmt in enumerate(self.values): for i, stmt in enumerate(self.values):