From 235b76c552117a953914439b0ce4fc3e6919decb Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 21 Aug 2017 20:13:29 +0300 Subject: [PATCH] PY-16968 Consider variadic keyword arguments mapped to keyword-only parameters We already to it for regular (positional/keyword) parameters even though (**kwargs) is not strictly compatible with (arg1, arg2, ...). Now we do it for (*, kwarg1, kwarg2, ...). We don't know much about **kwargs so it's better not to show any warnings here. --- .../python/psi/impl/PyCallExpressionHelper.java | 1 + .../kwargsAgainstKeywordOnly.py | 10 ++++++++++ .../inspections/PyArgumentListInspectionTest.java | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 python/testData/inspections/PyArgumentListInspection/kwargsAgainstKeywordOnly.py diff --git a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java index d520c8386f05..7a9dd4f7127e 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java +++ b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java @@ -921,6 +921,7 @@ public class PyCallExpressionHelper { } else { parametersMappedToVariadicKeywordArguments.add(parameter); + mappedVariadicArgumentsToParameters = true; } } else { diff --git a/python/testData/inspections/PyArgumentListInspection/kwargsAgainstKeywordOnly.py b/python/testData/inspections/PyArgumentListInspection/kwargsAgainstKeywordOnly.py new file mode 100644 index 000000000000..cbe9a989988d --- /dev/null +++ b/python/testData/inspections/PyArgumentListInspection/kwargsAgainstKeywordOnly.py @@ -0,0 +1,10 @@ +def f1(arg): + return 2 + +def f2(*, arg): + return 2 + + +def test(**kwargs): + f1(**kwargs) + f2(**kwargs) diff --git a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java index ccf903d425b9..97efabafbd04 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java @@ -322,6 +322,11 @@ public class PyArgumentListInspectionTest extends PyTestCase { runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); } + // PY-16968 + public void testKwargsAgainstKeywordOnly() { + runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest); + } + private void doMultiFileTest() { final String folderPath = "inspections/PyArgumentListInspection/" + getTestName(false) + "/";