diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index 6a73375..e067c0a 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -286,19 +286,27 @@ class ErrorFinder(Normalizer): if node.parent.type == 'del_stmt': self._add_syntax_error("can't use starred expression here", node.parent) else: - starred = [c for c in node.children if c.type == 'star_expr'] - if len(starred) > 1: - message = "two starred expressions in assignment" - self._add_syntax_error(message, starred[1]) - "can't use starred expression here" + is_definition = True + if is_definition: + args = [c for c in node.children if c != ','] + starred = [c for c in args if c.type == 'star_expr'] + if len(starred) > 1: + message = "two starred expressions in assignment" + self._add_syntax_error(message, starred[1]) + elif starred: + count = args.index(starred[0]) + if count >= 256: + message = "too many expressions in star-unpacking assignment" + self._add_syntax_error(message, starred[0]) elif node.type == 'star_expr': if node.parent.type not in _STAR_EXPR_PARENTS: message = "starred assignment target must be in a list or tuple" self._add_syntax_error(message, node) if node.parent.type == 'testlist_comp': # [*[] for a in [1]] - message = "iterable unpacking cannot be used in comprehension" - self._add_syntax_error(message, node) + if node.parent.children[0] == node: + message = "iterable unpacking cannot be used in comprehension" + self._add_syntax_error(message, node) elif node.type == 'comp_for': # Some of the nodes here are already used, so no else if expr_list = node.children[1 + int(node.children[0] == 'async')] diff --git a/test/normalizer_issue_files/allowed_syntax.py b/test/normalizer_issue_files/allowed_syntax.py index 3607450..4927e1b 100644 --- a/test/normalizer_issue_files/allowed_syntax.py +++ b/test/normalizer_issue_files/allowed_syntax.py @@ -51,6 +51,9 @@ class X(): nonlocal a +a = *args, *args + + def glob(): global x y: foo = x diff --git a/test/test_python_errors.py b/test/test_python_errors.py index ea7d227..5059d56 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -290,20 +290,15 @@ def test_default_except_error_postition(): ('{**{} for a in [1]}', '3.5'), ('"s" b""', '3.5'), ('b"รค"', '3.5'), - #('(%s *d) = x' % ('a,' * 256), '3.5') + ('(%s *d) = x' % ('a,' * 256), '3.6') ] ) def test_python_exception_matches_version(code, version): if '.'.join(str(v) for v in sys.version_info[:2]) != version: pytest.skip() + wanted, line_nr = _get_actual_exception(code) error, = _get_error_list(code) - try: - compile(code, '', 'exec') - except (SyntaxError, IndentationError) as e: - wanted = e.__class__.__name__ + ': ' + e.msg - else: - assert False, "The piece of code should raise an exception." assert wanted == error.message