From e496b07b6342f6182225a60aad6031d7ad08f24d Mon Sep 17 00:00:00 2001 From: Robin Fourcade <29704178+RobinFrcd@users.noreply.github.com> Date: Wed, 4 Dec 2019 17:21:22 +0100 Subject: [PATCH] Fix trailing comma error --- parso/python/errors.py | 2 +- test/test_python_errors.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/parso/python/errors.py b/parso/python/errors.py index 6bf0d17..d68d719 100644 --- a/parso/python/errors.py +++ b/parso/python/errors.py @@ -586,7 +586,7 @@ class _TrailingImportComma(SyntaxRule): message = "trailing comma not allowed without surrounding parentheses" def is_issue(self, node): - if node.children[-1] == ',': + if node.children[-1] == ',' and node.parent.children[-1] != ')': return True diff --git a/test/test_python_errors.py b/test/test_python_errors.py index 71a67eb..07fb390 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -307,3 +307,15 @@ def test_invalid_fstrings(code, message): """ error, = _get_error_list(code, version='3.6') assert message in error.message + + +@pytest.mark.parametrize( + 'code', [ + "from foo import (\nbar,\n rab,\n)", + "from foo import (bar, rab, )", + ] +) +def test_trailing_comma(code): + errors = _get_error_list(code) + assert not errors +