Fix an issue with starred arguments and if they are defined or used.

This commit is contained in:
Dave Halter
2017-07-30 18:42:36 +02:00
parent 94ce899a86
commit 45b965063e
2 changed files with 17 additions and 3 deletions

View File

@@ -286,8 +286,20 @@ class ErrorFinder(Normalizer):
if node.parent.type == 'del_stmt':
self._add_syntax_error("can't use starred expression here", node.parent)
else:
is_definition = True
if is_definition:
def is_definition(node, ancestor):
if ancestor is None:
return False
type_ = ancestor.type
if type_ == 'trailer':
return False
if type_ == 'expr_stmt':
return node.start_pos < ancestor.children[-1].start_pos
return is_definition(node, ancestor.parent)
if is_definition(node, node.parent):
args = [c for c in node.children if c != ',']
starred = [c for c in args if c.type == 'star_expr']
if len(starred) > 1:
@@ -304,7 +316,7 @@ class ErrorFinder(Normalizer):
self._add_syntax_error(message, node)
if node.parent.type == 'testlist_comp':
# [*[] for a in [1]]
if node.parent.children[0] == node:
if node.parent.children[1].type == 'comp_for':
message = "iterable unpacking cannot be used in comprehension"
self._add_syntax_error(message, node)
elif node.type == 'comp_for':

View File

@@ -52,6 +52,8 @@ class X():
a = *args, *args
error[(*args, *args)] = 3
*args, *args
def glob():