mirror of
https://github.com/davidhalter/parso.git
synced 2026-08-12 02:42:49 +08:00
Parenthesized single starred expression (*x) is no longer valid anywhere in Python 3.9+
This commit is contained in:
+14
-7
@@ -753,6 +753,16 @@ class _StarExprRule(SyntaxRule):
|
|||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if self._normalizer.version >= (3, 9):
|
||||||
|
ancestor = node.parent
|
||||||
|
else:
|
||||||
|
ancestor = _skip_parens_bottom_up(node)
|
||||||
|
# starred expression not in tuple/list/set
|
||||||
|
if ancestor.type not in (*_STAR_EXPR_PARENTS, 'dictorsetmaker') \
|
||||||
|
and not (ancestor.type == 'atom' and ancestor.children[0] != '('):
|
||||||
|
self.add_issue(node, message="can't use starred expression here")
|
||||||
|
return
|
||||||
|
|
||||||
if check_delete_starred(node):
|
if check_delete_starred(node):
|
||||||
if self._normalizer.version >= (3, 9):
|
if self._normalizer.version >= (3, 9):
|
||||||
self.add_issue(node, message="cannot delete starred")
|
self.add_issue(node, message="cannot delete starred")
|
||||||
@@ -764,12 +774,6 @@ class _StarExprRule(SyntaxRule):
|
|||||||
# [*[] for a in [1]]
|
# [*[] for a in [1]]
|
||||||
if node.parent.children[1].type in _COMP_FOR_TYPES:
|
if node.parent.children[1].type in _COMP_FOR_TYPES:
|
||||||
self.add_issue(node, message=self.message_iterable_unpacking)
|
self.add_issue(node, message=self.message_iterable_unpacking)
|
||||||
return
|
|
||||||
|
|
||||||
ancestor = _skip_parens_bottom_up(node)
|
|
||||||
# starred expression not in tuple/list/set
|
|
||||||
if ancestor.type not in (*_STAR_EXPR_PARENTS, 'dictorsetmaker', 'atom'):
|
|
||||||
self.add_issue(node, message="can't use starred expression here")
|
|
||||||
|
|
||||||
|
|
||||||
@ErrorFinder.register_rule(types=_STAR_EXPR_PARENTS)
|
@ErrorFinder.register_rule(types=_STAR_EXPR_PARENTS)
|
||||||
@@ -1107,7 +1111,10 @@ class _CheckAssignmentRule(SyntaxRule):
|
|||||||
else:
|
else:
|
||||||
self.add_issue(node, message="can't use starred expression here")
|
self.add_issue(node, message="can't use starred expression here")
|
||||||
else:
|
else:
|
||||||
ancestor = _skip_parens_bottom_up(node)
|
if self._normalizer.version >= (3, 9):
|
||||||
|
ancestor = node.parent
|
||||||
|
else:
|
||||||
|
ancestor = _skip_parens_bottom_up(node)
|
||||||
if ancestor.type not in _STAR_EXPR_PARENTS and not is_aug_assign \
|
if ancestor.type not in _STAR_EXPR_PARENTS and not is_aug_assign \
|
||||||
and not (ancestor.type == 'atom' and ancestor.children[0] == '['):
|
and not (ancestor.type == 'atom' and ancestor.children[0] == '['):
|
||||||
message = "starred assignment target must be in a list or tuple"
|
message = "starred assignment target must be in a list or tuple"
|
||||||
|
|||||||
@@ -425,10 +425,6 @@ def test_unparenthesized_genexp(source, no_errors):
|
|||||||
('a, *b = 1', True),
|
('a, *b = 1', True),
|
||||||
('a, *b, c', True),
|
('a, *b, c', True),
|
||||||
('a, *b, c = 1', True),
|
('a, *b, c = 1', True),
|
||||||
('a, (*b), c', True),
|
|
||||||
('a, (*b), c = 1', True),
|
|
||||||
('a, ((*b)), c', True),
|
|
||||||
('a, ((*b)), c = 1', True),
|
|
||||||
('a, (*b, c), d', True),
|
('a, (*b, c), d', True),
|
||||||
('a, (*b, c), d = 1', True),
|
('a, (*b, c), d = 1', True),
|
||||||
('*a.b,', True),
|
('*a.b,', True),
|
||||||
@@ -455,6 +451,19 @@ def test_starred_expr(source, no_errors):
|
|||||||
assert bool(_get_error_list(source, version="3")) ^ no_errors
|
assert bool(_get_error_list(source, version="3")) ^ no_errors
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'code', [
|
||||||
|
'a, (*b), c',
|
||||||
|
'a, (*b), c = 1',
|
||||||
|
'a, ((*b)), c',
|
||||||
|
'a, ((*b)), c = 1',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_parenthesized_single_starred_expr(code):
|
||||||
|
assert not _get_error_list(code, version='3.8')
|
||||||
|
assert _get_error_list(code, version='3.9')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'code', [
|
'code', [
|
||||||
'() = ()',
|
'() = ()',
|
||||||
|
|||||||
Reference in New Issue
Block a user