Fix an issue with slice indexing.

This commit is contained in:
Dave Halter
2016-07-14 18:27:15 +02:00
parent 3a0008ea80
commit 218278af8d
3 changed files with 11 additions and 2 deletions

View File

@@ -378,7 +378,7 @@ class Evaluator(object):
pass pass
else: else:
if comp_for == ':': if comp_for == ':':
# Dict comprehensions have it at the 3rd index. # Dict comprehensions have a colon at the 3rd index.
try: try:
comp_for = c[1].children[3] comp_for = c[1].children[3]
except IndexError: except IndexError:

View File

@@ -821,7 +821,11 @@ def create_index_types(evaluator, index):
""" """
Handles slices in subscript nodes. Handles slices in subscript nodes.
""" """
if tree.is_node(index, 'subscript'): # subscript is a slice operation. if index == ':':
# Like array[:]
return set([Slice(evaluator, None, None, None)])
elif tree.is_node(index, 'subscript'): # subscript is a slice operation.
# Like array[:3]
result = [] result = []
for el in index.children: for el in index.children:
if el == ':': if el == ':':
@@ -835,4 +839,6 @@ def create_index_types(evaluator, index):
result += [None] * (3 - len(result)) result += [None] * (3 - len(result))
return set([Slice(evaluator, *result)]) return set([Slice(evaluator, *result)])
# No slices
return evaluator.eval_element(index) return evaluator.eval_element(index)

View File

@@ -39,6 +39,9 @@ b[8:]
#? list() #? list()
b[int():] b[int():]
#? list()
b[:]
class _StrangeSlice(): class _StrangeSlice():
def __getitem__(self, sliced): def __getitem__(self, sliced):