Commit 22b7ce25 authored by Stefan Behnel's avatar Stefan Behnel

make the parser correctly understand obj[1,] as passing a tuple as key

parent c6c3388c
...@@ -13,6 +13,8 @@ Features added ...@@ -13,6 +13,8 @@ Features added
Bugs fixed Bugs fixed
---------- ----------
* "obj[1,]" passed a single integer into the item getter instead of a tuple.
* Cyclic imports at module init time did not work in Py3. * Cyclic imports at module init time did not work in Py3.
* The names of C++ destructors for template classes were built incorrectly. * The names of C++ destructors for template classes were built incorrectly.
......
...@@ -49,7 +49,7 @@ cpdef p_call_parse_args(PyrexScanner s, bint allow_genexp = *) ...@@ -49,7 +49,7 @@ cpdef p_call_parse_args(PyrexScanner s, bint allow_genexp = *)
cdef p_call_build_packed_args(pos, positional_args, keyword_args, star_arg, starstar_arg) cdef p_call_build_packed_args(pos, positional_args, keyword_args, star_arg, starstar_arg)
cdef p_call(PyrexScanner s, function) cdef p_call(PyrexScanner s, function)
cdef p_index(PyrexScanner s, base) cdef p_index(PyrexScanner s, base)
cdef p_subscript_list(PyrexScanner s) cdef tuple p_subscript_list(PyrexScanner s)
cdef p_subscript(PyrexScanner s) cdef p_subscript(PyrexScanner s)
cdef p_slice_element(PyrexScanner s, follow_set) cdef p_slice_element(PyrexScanner s, follow_set)
cdef expect_ellipsis(PyrexScanner s) cdef expect_ellipsis(PyrexScanner s)
......
...@@ -503,14 +503,14 @@ def p_index(s, base): ...@@ -503,14 +503,14 @@ def p_index(s, base):
# s.sy == '[' # s.sy == '['
pos = s.position() pos = s.position()
s.next() s.next()
subscripts = p_subscript_list(s) subscripts, is_single_value = p_subscript_list(s)
if len(subscripts) == 1 and len(subscripts[0]) == 2: if is_single_value and len(subscripts[0]) == 2:
start, stop = subscripts[0] start, stop = subscripts[0]
result = ExprNodes.SliceIndexNode(pos, result = ExprNodes.SliceIndexNode(pos,
base = base, start = start, stop = stop) base = base, start = start, stop = stop)
else: else:
indexes = make_slice_nodes(pos, subscripts) indexes = make_slice_nodes(pos, subscripts)
if len(indexes) == 1: if is_single_value:
index = indexes[0] index = indexes[0]
else: else:
index = ExprNodes.TupleNode(pos, args = indexes) index = ExprNodes.TupleNode(pos, args = indexes)
...@@ -520,13 +520,15 @@ def p_index(s, base): ...@@ -520,13 +520,15 @@ def p_index(s, base):
return result return result
def p_subscript_list(s): def p_subscript_list(s):
is_single_value = True
items = [p_subscript(s)] items = [p_subscript(s)]
while s.sy == ',': while s.sy == ',':
is_single_value = False
s.next() s.next()
if s.sy == ']': if s.sy == ']':
break break
items.append(p_subscript(s)) items.append(p_subscript(s))
return items return items, is_single_value
#subscript: '.' '.' '.' | test | [test] ':' [test] [':' [test]] #subscript: '.' '.' '.' | test | [test] ':' [test] [':' [test]]
...@@ -2117,7 +2119,7 @@ def p_memoryviewslice_access(s, base_type_node): ...@@ -2117,7 +2119,7 @@ def p_memoryviewslice_access(s, base_type_node):
# s.sy == '[' # s.sy == '['
pos = s.position() pos = s.position()
s.next() s.next()
subscripts = p_subscript_list(s) subscripts, _ = p_subscript_list(s)
# make sure each entry in subscripts is a slice # make sure each entry in subscripts is a slice
for subscript in subscripts: for subscript in subscripts:
if len(subscript) < 2: if len(subscript) < 2:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment