mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use union of types of members as iteration type for tuples
This commit is contained in:
@@ -386,6 +386,14 @@ public class PyTargetExpressionImpl extends PyPresentableElementImpl<PyTargetExp
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (iterableType instanceof PyTupleType) {
|
||||
final PyTupleType tupleType = (PyTupleType)iterableType;
|
||||
final List<PyType> memberTypes = new ArrayList<PyType>();
|
||||
for (int i = 0; i < tupleType.getElementCount(); i++) {
|
||||
memberTypes.add(tupleType.getElementType(i));
|
||||
}
|
||||
return PyUnionType.union(memberTypes);
|
||||
}
|
||||
else if (iterableType instanceof PyUnionType) {
|
||||
final Collection<PyType> members = ((PyUnionType)iterableType).getMembers();
|
||||
final List<PyType> iterationTypes = new ArrayList<PyType>();
|
||||
|
||||
@@ -812,6 +812,13 @@ public class PyTypeTest extends PyTestCase {
|
||||
" expr, foo = xs\n");
|
||||
}
|
||||
|
||||
public void testTupleIterationType() {
|
||||
doTest("int | str",
|
||||
"xs = (1, 'a')\n" +
|
||||
"for expr in xs:\n" +
|
||||
" pass\n");
|
||||
}
|
||||
|
||||
private static TypeEvalContext getTypeEvalContext(@NotNull PyExpression element) {
|
||||
return TypeEvalContext.userInitiated(element.getContainingFile()).withTracing();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user