diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2012-11-10 15:04:47 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2012-11-10 15:04:47 +0100 |
commit | 24cdbff2669d20e03c70ddad85d2e36938079962 (patch) | |
tree | c0fabb2d60c8ab2567940d9a70026fc5f798097e | |
parent | 15dce27569dd7624671964ad37d46810f3444ee7 (diff) | |
download | cython-24cdbff2669d20e03c70ddad85d2e36938079962.tar.gz |
make the parser correctly understand obj[1,] as passing a tuple as key
--HG--
extra : transplant_source : %5D%AE%1EG%B0%F9%A2%C2%1A%FB5%A6%A65%A5%EE%C4%AC%C4%AD
-rw-r--r-- | CHANGES.rst | 2 | ||||
-rw-r--r-- | Cython/Compiler/Parsing.pxd | 2 | ||||
-rw-r--r-- | Cython/Compiler/Parsing.py | 12 |
3 files changed, 10 insertions, 6 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 2884dfad9..27556581a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,8 @@ Features added 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. * The names of C++ destructors for template classes were built incorrectly. diff --git a/Cython/Compiler/Parsing.pxd b/Cython/Compiler/Parsing.pxd index f2aa2dbc3..2140e290c 100644 --- a/Cython/Compiler/Parsing.pxd +++ b/Cython/Compiler/Parsing.pxd @@ -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(PyrexScanner s, function) 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_slice_element(PyrexScanner s, follow_set) cdef expect_ellipsis(PyrexScanner s) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 63dd19faa..2dba4931a 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -503,14 +503,14 @@ def p_index(s, base): # s.sy == '[' pos = s.position() s.next() - subscripts = p_subscript_list(s) - if len(subscripts) == 1 and len(subscripts[0]) == 2: + subscripts, is_single_value = p_subscript_list(s) + if is_single_value and len(subscripts[0]) == 2: start, stop = subscripts[0] result = ExprNodes.SliceIndexNode(pos, base = base, start = start, stop = stop) else: indexes = make_slice_nodes(pos, subscripts) - if len(indexes) == 1: + if is_single_value: index = indexes[0] else: index = ExprNodes.TupleNode(pos, args = indexes) @@ -520,13 +520,15 @@ def p_index(s, base): return result def p_subscript_list(s): + is_single_value = True items = [p_subscript(s)] while s.sy == ',': + is_single_value = False s.next() if s.sy == ']': break items.append(p_subscript(s)) - return items + return items, is_single_value #subscript: '.' '.' '.' | test | [test] ':' [test] [':' [test]] @@ -2112,7 +2114,7 @@ def p_memoryviewslice_access(s, base_type_node): # s.sy == '[' pos = s.position() s.next() - subscripts = p_subscript_list(s) + subscripts, _ = p_subscript_list(s) # make sure each entry in subscripts is a slice for subscript in subscripts: if len(subscript) < 2: |