mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 12:54:29 +08:00
allow trailing comma <3.6, test both postive/negative cases
This commit is contained in:
@@ -800,9 +800,18 @@ class _ArglistRule(SyntaxRule):
|
|||||||
|
|
||||||
if argument.type == 'argument':
|
if argument.type == 'argument':
|
||||||
first = argument.children[0]
|
first = argument.children[0]
|
||||||
if argument.children[1].type in _COMP_FOR_TYPES and len(node.children) >= 2:
|
if (
|
||||||
# a(a, b for b in c)
|
argument.children[1].type in _COMP_FOR_TYPES
|
||||||
|
and len(node.children) >= 2
|
||||||
|
):
|
||||||
|
if self._normalizer.version >= (3, 7):
|
||||||
return True
|
return True
|
||||||
|
elif len(node.children) == 2 and node.children[1] == ",":
|
||||||
|
# trailing comma allowed until 3.7
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
if first in ('*', '**'):
|
if first in ('*', '**'):
|
||||||
if first == '*':
|
if first == '*':
|
||||||
if kw_unpacking_only:
|
if kw_unpacking_only:
|
||||||
|
|||||||
@@ -378,12 +378,17 @@ def test_repeated_kwarg():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'source', [
|
('source', 'no_errors', 'version'), [
|
||||||
'a(a for a in b,)'
|
('a(a for a in b,)', True, '3.6'),
|
||||||
'a(a for a in b, a)',
|
('a(a for a in b,)', False, '3.7'),
|
||||||
'a(a, a for a in b)',
|
('a(a for a in b, a)', False, None),
|
||||||
'a(a, b, a for a in b, c, d)',
|
('a(a, a for a in b)', False, None),
|
||||||
|
('a(a, b, a for a in b, c, d)', False, None),
|
||||||
|
('a(a for a in b)', True, None),
|
||||||
|
('a((a for a in b), c)', True, None),
|
||||||
|
('a(c, (a for a in b))', True, None),
|
||||||
|
('a(a, (a for a in b), c)', True, None),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_unparenthesized_genexp(source):
|
def test_unparenthesized_genexp(source, no_errors, version):
|
||||||
assert _get_error_list(source)
|
assert bool(_get_error_list(source, version=version)) ^ no_errors
|
||||||
|
|||||||
Reference in New Issue
Block a user