mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-38928 Parentheses around unpacking for "for" loop target variables break type inference
GitOrigin-RevId: 9debb720880dd77b47c325e426e2d76c74135192
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0173303e0b
commit
3a8596a0e3
+3
-2
@@ -301,8 +301,9 @@ public class PyTargetExpressionImpl extends PyBaseElementImpl<PyTargetExpression
|
||||
if (source != null) {
|
||||
final PyType sourceType = context.getType(source);
|
||||
final PyType type = getIterationType(sourceType, source, this, context);
|
||||
if (type instanceof PyTupleType && target instanceof PyTupleExpression) {
|
||||
return PyTypeChecker.getTargetTypeFromTupleAssignment(this, (PyTupleExpression)target, (PyTupleType)type);
|
||||
target = PyPsiUtils.flattenParens(target);
|
||||
if (type instanceof PyTupleType tupleType && target instanceof PyTupleExpression tupleExpression) {
|
||||
return PyTypeChecker.getTargetTypeFromTupleAssignment(this, tupleExpression, tupleType);
|
||||
}
|
||||
if (target == this && type != null) {
|
||||
return type;
|
||||
|
||||
@@ -1114,6 +1114,17 @@ public class PyTypeTest extends PyTestCase {
|
||||
"(a, (_, expr)) = (1, xs) ");
|
||||
}
|
||||
|
||||
// PY-38928
|
||||
public void testIterateListOfTuples() {
|
||||
doTest(
|
||||
"str",
|
||||
"""
|
||||
for ((_, expr)) in [(1, 'foo')]:
|
||||
pass
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
public void testConstructorUnification() {
|
||||
doTest("C[int]",
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user