diff --git a/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java b/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java index eecb8e03a0d3..97a5a365f2ea 100644 --- a/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java @@ -16,6 +16,7 @@ package com.jetbrains.python.inspections; import com.intellij.codeInspection.LocalInspectionToolSession; +import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElementVisitor; @@ -138,7 +139,7 @@ public class PyArgumentListInspection extends PyInspection { holder.registerProblem(arg, PyBundle.message("INSP.duplicate.star.arg")); } if (flags.contains(CallArgumentsMapping.ArgFlag.IS_POS_PAST_KWD)) { - holder.registerProblem(arg, PyBundle.message("INSP.cannot.appear.past.keyword.arg")); + holder.registerProblem(arg, PyBundle.message("INSP.cannot.appear.past.keyword.arg"), ProblemHighlightType.ERROR); } if (flags.contains(CallArgumentsMapping.ArgFlag.IS_UNMAPPED)) { holder.registerProblem(arg, PyBundle.message("INSP.unexpected.arg")); diff --git a/python/src/com/jetbrains/python/psi/impl/CallArgumentsMappingImpl.java b/python/src/com/jetbrains/python/psi/impl/CallArgumentsMappingImpl.java index 432a9ceb1099..5ce309533d62 100644 --- a/python/src/com/jetbrains/python/psi/impl/CallArgumentsMappingImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/CallArgumentsMappingImpl.java @@ -180,15 +180,9 @@ public class CallArgumentsMappingImpl implements CallArgumentsMapping { for (PyExpression arg : unmatched_subargs) { markArgument(arg, ArgFlag.IS_UNMAPPED); } - // mark past-bound positional args - i = positional_bound; - while (i parameter_by_name = new LinkedHashMap(); @@ -352,6 +346,19 @@ public class CallArgumentsMappingImpl implements CallArgumentsMapping { } } + private void markPastBoundPositionalArguments(PyExpression[] arguments, int positionalBound) { + boolean seenKwArg = false; + for(int i=positionalBound; i3) f3(b=2, a=1) f3(b=1, b=2, a=1) f3(1, b=2) -f3(a=1, 2) +f3(a=1, 2) def f4(a, *b): pass @@ -52,4 +52,4 @@ f4(1, 2) f4(1, 2, 3) f4(1, *(2, 3)) f4(*(1,2,3)) -f4(a=1, 2, 3) +f4(a=1, 2, 3) diff --git a/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer.py b/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer.py new file mode 100644 index 000000000000..6601fc76d18c --- /dev/null +++ b/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer.py @@ -0,0 +1,5 @@ +def foo(**kwargs): pass + +two = 0 +kw = {} +foo(**kw, two=1) diff --git a/python/testData/inspections/PyArgumentListInspection/py1268.py b/python/testData/inspections/PyArgumentListInspection/py1268.py index e6c578134dba..4e33321bb520 100644 --- a/python/testData/inspections/PyArgumentListInspection/py1268.py +++ b/python/testData/inspections/PyArgumentListInspection/py1268.py @@ -19,7 +19,7 @@ def f2(a, b, c=1, *d): f2(c=3, *(1,2)) f2(1,2,3, *(1,2)) f2(*(1,2), c=20) -f2(*(1,2), 20) # fail: positional past * +f2(*(1,2), 20) # fail: positional past * def f3(a=1, b=2, c=3, *d): return a,b,c,d diff --git a/python/testData/inspections/PyArgumentListInspection/py3k.py b/python/testData/inspections/PyArgumentListInspection/py3k.py index bb85744ba8bb..a43c848f77d3 100644 --- a/python/testData/inspections/PyArgumentListInspection/py3k.py +++ b/python/testData/inspections/PyArgumentListInspection/py3k.py @@ -13,7 +13,7 @@ namedpast(1,2,3, foo='a') # pass namedpast(*args, foo='b') # pass namedpast(foo='c') # pass namedpast() # pass -namedpast(foo='1', 2) # fail +namedpast(foo='1', 2) # fail def a23(a, *b, c=1): pass @@ -21,7 +21,7 @@ def a23(a, *b, c=1): a23(1,2,3, c=10) # pass a23(1,2,3, c=10, a=1) # fail a23(c=10, a=1) # pass -a23(c=10, 1) # fail +a23(c=10, 1) # fail a23(*args, a=1) # fail a23(*args, c=1) # pass diff --git a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java index affc095d1c3a..703b2ebbc9bd 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java @@ -168,4 +168,8 @@ public class PyArgumentListInspectionTest extends PyTestCase { public void testDictFromKeys() { doTest(); } + + public void testParameterWithDefaultAfterKeywordContainer() { // PY-9934 + doTest(); + } }