Ref<PyType> (@NotNull PyBinaryExpression multiplication, @NotNull TypeEvalContext context) { final PyTupleType leftTupleType = as(context.getType(multiplication.getLeftExpression()), PyTupleType.class); if (leftTupleType == null) { return null; } PyExpression rightExpression = multiplication.getRightExpression(); if (rightExpression instanceof PyReferenceExpression) { final PsiElement target = ((PyReferenceExpression)rightExpression).getReference().resolve(); if (target instanceof PyTargetExpression) { rightExpression = ((PyTargetExpression)target).findAssignedValue(); } } if (rightExpression instanceof PyNumericLiteralExpression && ((PyNumericLiteralExpression)rightExpression).isIntegerLiteral()) { if (leftTupleType.isHomogeneous()) { return Ref.create(leftTupleType); } final int multiplier = ((PyNumericLiteralExpression)rightExpression).getBigIntegerValue().intValue(); final int originalSize = leftTupleType.getElementCount(); // Heuristic if (originalSize * multiplier <= 20) { final PyType[] elementTypes = new PyType[leftTupleType.getElementCount() * multiplier]; for (int i = 0; i < multiplier; i++) { for (int j = 0; j < originalSize; j++) { elementTypes[i * originalSize + j] = leftTupleType.getElementType(j); } } return Ref.create(PyTupleType.create(multiplication, Arrays.asList(elementTypes))); } } return null; }