PY-52760 Type checker fails at tuple unpacking into a dictionary

GitOrigin-RevId: dbf1181099501764ac9b0d42813b37b48882379c
This commit is contained in:
Petr
2024-04-02 15:05:56 +00:00
committed by intellij-monorepo-bot
parent 2d3d4c8470
commit cdfef53944
2 changed files with 23 additions and 4 deletions
@@ -11,7 +11,6 @@ import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil
import com.jetbrains.python.psi.*
import com.jetbrains.python.psi.impl.PyBuiltinCache
import com.jetbrains.python.psi.resolve.PyResolveContext
import com.jetbrains.python.pyi.PyiUtil
object PyCollectionTypeUtil {
@@ -360,9 +359,8 @@ object PyCollectionTypeUtil {
}
var rightValue = assignment.assignedValue
if (tupleParent != null && rightValue is PyTupleExpression) {
val rightTuple = rightValue as PyTupleExpression?
val rightElements = rightTuple!!.elements
if (tupleParent != null) {
val rightElements = PyUtil.flattenedParensAndLists(rightValue)
val indexInAssignment = tupleParent.elements.indexOf(node)
if (indexInAssignment < rightElements.size) {
rightValue = rightElements[indexInAssignment]
@@ -1125,6 +1125,27 @@ public class PyTypeTest extends PyTestCase {
);
}
// PY-52760
public void testTupleLiteralDestructuringAssignmentToDict() {
doTest(
"Dict[str, int]",
"""
expr = {}
expr["a"], _ = (1, 2)
"""
);
}
public void testListLiteralDestructuringAssignmentToDict() {
doTest(
"Dict[str, int]",
"""
expr = {}
expr["a"], _ = [1, 2]
"""
);
}
public void testConstructorUnification() {
doTest("C[int]",
"""