From 8e3e414a6645275c70845e2620105d431a9fd402 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 31 Oct 2013 20:32:35 +0100 Subject: [PATCH] verify argument list even if unable to resolve callee (PY-10351) --- .../psi/impl/CallArgumentsMappingImpl.java | 73 ++++++++++++------- .../python/psi/impl/PyArgumentListImpl.java | 9 ++- ...ameterWithDefaultAfterKeywordContainer2.py | 8 ++ .../PyArgumentListInspectionTest.java | 4 + 4 files changed, 64 insertions(+), 30 deletions(-) create mode 100644 python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer2.py diff --git a/python/src/com/jetbrains/python/psi/impl/CallArgumentsMappingImpl.java b/python/src/com/jetbrains/python/psi/impl/CallArgumentsMappingImpl.java index 5ce309533d62..692ff0052b10 100644 --- a/python/src/com/jetbrains/python/psi/impl/CallArgumentsMappingImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/CallArgumentsMappingImpl.java @@ -65,29 +65,9 @@ public class CallArgumentsMappingImpl implements CallArgumentsMapping { public void mapArguments(PyCallExpression.PyMarkedCallee resolved_callee, @NotNull TypeEvalContext context) { PyExpression[] arguments = myArgumentList.getArguments(); myMarkedCallee = resolved_callee; - List unmatched_args = new LinkedList(); - Collections.addAll(unmatched_args, arguments); final List unmatched_subargs = new LinkedList(); // unmatched nested arguments will go here - // detect starred args - for (PyExpression arg : arguments) { - if (arg instanceof PyStarArgument) { - PyStarArgument star_arg = (PyStarArgument)arg; - if (star_arg.isKeyword()) { - if (myKwdArg == null) myKwdArg = star_arg; - else { - markArgument(arg, ArgFlag.IS_DUP_KWD); - unmatched_args.remove(arg); - } - } - else { - if (myTupleArg == null) myTupleArg = star_arg; - else { - markArgument(arg, ArgFlag.IS_DUP_TUPLE); - unmatched_args.remove(arg); - } - } - } - } + List unmatched_args = verifyArguments(); + final List parameters = PyUtil.getParameters(myMarkedCallee.getCallable(), context); // prepare parameter slots Map slots = new LinkedHashMap(); @@ -181,7 +161,6 @@ public class CallArgumentsMappingImpl implements CallArgumentsMapping { markArgument(arg, ArgFlag.IS_UNMAPPED); } - markPastBoundPositionalArguments(arguments, positional_bound); boolean seen_named_args = false; // map named args to named params if possible @@ -346,15 +325,53 @@ public class CallArgumentsMappingImpl implements CallArgumentsMapping { } } - private void markPastBoundPositionalArguments(PyExpression[] arguments, int positionalBound) { + public List verifyArguments() { + List unmatched_args = new LinkedList(); + Collections.addAll(unmatched_args, myArgumentList.getArguments()); + // detect starred args + for (PyExpression arg : myArgumentList.getArguments()) { + if (arg instanceof PyStarArgument) { + PyStarArgument star_arg = (PyStarArgument)arg; + if (star_arg.isKeyword()) { + if (myKwdArg == null) myKwdArg = star_arg; + else { + markArgument(arg, ArgFlag.IS_DUP_KWD); + unmatched_args.remove(arg); + } + } + else { + if (myTupleArg == null) myTupleArg = star_arg; + else { + markArgument(arg, ArgFlag.IS_DUP_TUPLE); + unmatched_args.remove(arg); + } + } + } + } + + markPastBoundPositionalArguments(myArgumentList.getArguments()); + return unmatched_args; + } + + private void markPastBoundPositionalArguments(PyExpression[] arguments) { boolean seenKwArg = false; - for(int i=positionalBound; ifoo=1) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java index 703b2ebbc9bd..fabba0c2458f 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java @@ -172,4 +172,8 @@ public class PyArgumentListInspectionTest extends PyTestCase { public void testParameterWithDefaultAfterKeywordContainer() { // PY-9934 doTest(); } + + public void testParameterWithDefaultAfterKeywordContainer2() { // PY-10351 + doTest(); + } }