PY-21156 Resolve to keyword argument for dict call

This commit is contained in:
Valentina Kiryushkina
2017-05-15 14:37:55 +03:00
parent 78d9f96481
commit ec675c1d80
4 changed files with 9 additions and 4 deletions
@@ -395,8 +395,8 @@ public class PySubstitutionChunkReference extends PsiReferenceBase<PyStringLiter
private PyExpression resolveKeywordPercent(@NotNull PyExpression expression, @NotNull String key) {
final PyExpression containedExpr = PyPsiUtils.flattenParens(expression);
final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(myTypeEvalContext);
if (containedExpr instanceof PyDictLiteralExpression) {
final Ref<PyExpression> resolvedRef = getElementFromDictLiteral((PyDictLiteralExpression)containedExpr, key, resolveContext);
if (PyUtil.instanceOf(containedExpr, PyDictLiteralExpression.class, PyCallExpression.class)) {
final Ref<PyExpression> resolvedRef = getElementFromDictLiteral(containedExpr, key, resolveContext);
return resolvedRef != null ? resolvedRef.get() : containedExpr;
}
else if (PyUtil.instanceOf(containedExpr, PyLiteralExpression.class, PySetLiteralExpression.class,
@@ -457,7 +457,6 @@ public class PySubstitutionChunkReference extends PsiReferenceBase<PyStringLiter
return containedExpression;
}
@Nullable
private static PyArgumentList getArgumentList(final PsiElement original) {
final PsiElement pyReferenceExpression = PsiTreeUtil.getParentOfType(original, PyReferenceExpression.class);
@@ -0,0 +1 @@
<warning descr="Mapping key \"third\" is unused">'{first}, {second}, {third}'</warning>.format(**dict(first='a', second='b'))
@@ -719,7 +719,7 @@ public class PyResolveTest extends PyResolveTestCase {
//PY-2748
public void testFormatStringPackedDictCall() {
PsiElement target = resolve();
assertInstanceOf(target, PyStarArgument.class);
assertInstanceOf(target, PyKeywordArgument.class);
}
//PY-2748
@@ -208,6 +208,11 @@ public class PyStringFormatInspectionTest extends PyTestCase {
public void testPackedStringTooFewArguments() {
doTest();
}
// PY-21156
public void testPackedDictCallUnusedMappingKey() {
doTest();
}
private void doTest() {
myFixture.configureByFile(TEST_DIRECTORY + getTestName(false) + ".py");