Commit 804c439c authored by Stefan Behnel's avatar Stefan Behnel

let the parser detect '*a = ...' and provide a helpful error message

parent 0da3fcb6
...@@ -1073,6 +1073,12 @@ def p_nonlocal_statement(s): ...@@ -1073,6 +1073,12 @@ def p_nonlocal_statement(s):
def p_expression_or_assignment(s): def p_expression_or_assignment(s):
expr_list = [p_testlist_star_expr(s)] expr_list = [p_testlist_star_expr(s)]
if s.sy == '=' and expr_list[0].is_starred:
# This is a common enough error to make when learning Cython to let
# it fail as early as possible and give a very clear error message.
s.error("a starred assignment target must be in a list or tuple"
" - maybe you meant to use an index assignment: var[0] = ...",
pos=expr_list[0].pos)
while s.sy == '=': while s.sy == '=':
s.next() s.next()
if s.sy == 'yield': if s.sy == 'yield':
......
# mode: error
# very common mistake for new users (handled early by the parser)
def no_tuple_assignment():
*a = [1]
_ERRORS = u"""
6:4: a starred assignment target must be in a list or tuple - maybe you meant to use an index assignment: var[0] = ...
"""
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