mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-16 01:17:13 +08:00
Add issue 'too many expressions in star-unpacking assignment'
This commit is contained in:
@@ -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')]
|
||||
|
||||
@@ -51,6 +51,9 @@ class X():
|
||||
nonlocal a
|
||||
|
||||
|
||||
a = *args, *args
|
||||
|
||||
|
||||
def glob():
|
||||
global x
|
||||
y: foo = x
|
||||
|
||||
@@ -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, '<unknown>', '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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user