From 92396a9a16e5e4fb8a5ef9f3b5ad6109a6302a92 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Sat, 23 May 2020 17:44:28 +0300 Subject: [PATCH] allow trailing comma <3.6, test both postive/negative cases --- parso/python/errors.py | 15 ++++++++++++--- test/test_python_errors.py | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/parso/python/errors.py b/parso/python/errors.py index 2142dd1..4d9bff2 100644 --- a/parso/python/errors.py +++ b/parso/python/errors.py @@ -800,9 +800,18 @@ class _ArglistRule(SyntaxRule): if argument.type == 'argument': first = argument.children[0] - if argument.children[1].type in _COMP_FOR_TYPES and len(node.children) >= 2: - # a(a, b for b in c) - return True + if ( + argument.children[1].type in _COMP_FOR_TYPES + and len(node.children) >= 2 + ): + if self._normalizer.version >= (3, 7): + 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 == '*': if kw_unpacking_only: diff --git a/test/test_python_errors.py b/test/test_python_errors.py index 3eba4af..94ff0c7 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -378,12 +378,17 @@ def test_repeated_kwarg(): @pytest.mark.parametrize( - 'source', [ - 'a(a for a in b,)' - 'a(a for a in b, a)', - 'a(a, a for a in b)', - 'a(a, b, a for a in b, c, d)', + ('source', 'no_errors', 'version'), [ + ('a(a for a in b,)', True, '3.6'), + ('a(a for a in b,)', False, '3.7'), + ('a(a for a in b, a)', False, None), + ('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): - assert _get_error_list(source) +def test_unparenthesized_genexp(source, no_errors, version): + assert bool(_get_error_list(source, version=version)) ^ no_errors