Fix calculating arguments for __setitem__ (PY-27949)

This commit is contained in:
Semyon Proshev
2018-03-15 17:45:29 +03:00
parent 19699cde61
commit c6f6e8cebd
3 changed files with 18 additions and 0 deletions
@@ -15,9 +15,11 @@
*/
package com.jetbrains.python.psi;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -35,6 +37,12 @@ public interface PySubscriptionExpression extends PyQualifiedExpression, PyCallS
@NotNull
@Override
default List<PyExpression> getArguments(@Nullable PyCallable resolvedCallee) {
if (AccessDirection.of(this) == AccessDirection.WRITE) {
final PsiElement parent = getParent();
if (parent instanceof PyAssignmentStatement) {
return Arrays.asList(getIndexExpression(), ((PyAssignmentStatement)parent).getAssignedValue());
}
}
return Collections.singletonList(getIndexExpression());
}
@@ -0,0 +1,5 @@
from typing import Dict
data = {} # type: Dict[int, str]
data[<weak_warning descr="Expected type 'int' (matched generic type '_KT'), got 'str' instead">'test'</weak_warning>] = <weak_warning descr="Expected type 'str' (matched generic type '_VT'), got 'int' instead">12</weak_warning>
data[12] = 'test'
@@ -530,4 +530,9 @@ public class PyTypeCheckerInspectionTest extends PyInspectionTestCase {
public void testOverloadedFunctionAssignedToTargetInStub() {
doMultiFileTest();
}
// PY-27949
public void testAssigningToDictEntry() {
doTest();
}
}