Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 22b7ce2

Browse files
committed
make the parser correctly understand obj[1,] as passing a tuple as key
1 parent c6c3388 commit 22b7ce2

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Features added
1313
Bugs fixed
1414
----------
1515

16+
* "obj[1,]" passed a single integer into the item getter instead of a tuple.
17+
1618
* Cyclic imports at module init time did not work in Py3.
1719

1820
* The names of C++ destructors for template classes were built incorrectly.

Cython/Compiler/Parsing.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cpdef p_call_parse_args(PyrexScanner s, bint allow_genexp = *)
4949
cdef p_call_build_packed_args(pos, positional_args, keyword_args, star_arg, starstar_arg)
5050
cdef p_call(PyrexScanner s, function)
5151
cdef p_index(PyrexScanner s, base)
52-
cdef p_subscript_list(PyrexScanner s)
52+
cdef tuple p_subscript_list(PyrexScanner s)
5353
cdef p_subscript(PyrexScanner s)
5454
cdef p_slice_element(PyrexScanner s, follow_set)
5555
cdef expect_ellipsis(PyrexScanner s)

Cython/Compiler/Parsing.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,14 @@ def p_index(s, base):
503503
# s.sy == '['
504504
pos = s.position()
505505
s.next()
506-
subscripts = p_subscript_list(s)
507-
if len(subscripts) == 1 and len(subscripts[0]) == 2:
506+
subscripts, is_single_value = p_subscript_list(s)
507+
if is_single_value and len(subscripts[0]) == 2:
508508
start, stop = subscripts[0]
509509
result = ExprNodes.SliceIndexNode(pos,
510510
base = base, start = start, stop = stop)
511511
else:
512512
indexes = make_slice_nodes(pos, subscripts)
513-
if len(indexes) == 1:
513+
if is_single_value:
514514
index = indexes[0]
515515
else:
516516
index = ExprNodes.TupleNode(pos, args = indexes)
@@ -520,13 +520,15 @@ def p_index(s, base):
520520
return result
521521

522522
def p_subscript_list(s):
523+
is_single_value = True
523524
items = [p_subscript(s)]
524525
while s.sy == ',':
526+
is_single_value = False
525527
s.next()
526528
if s.sy == ']':
527529
break
528530
items.append(p_subscript(s))
529-
return items
531+
return items, is_single_value
530532

531533
#subscript: '.' '.' '.' | test | [test] ':' [test] [':' [test]]
532534

@@ -2117,7 +2119,7 @@ def p_memoryviewslice_access(s, base_type_node):
21172119
# s.sy == '['
21182120
pos = s.position()
21192121
s.next()
2120-
subscripts = p_subscript_list(s)
2122+
subscripts, _ = p_subscript_list(s)
21212123
# make sure each entry in subscripts is a slice
21222124
for subscript in subscripts:
21232125
if len(subscript) < 2:

0 commit comments

Comments
 (0)