void (PyExpression lhs, PyExpression rhs, List<Pair<PyExpression, PyExpression>> map) { // cast for convenience PySequenceExpression lhs_tuple = null; PyExpression lhs_one = null; if (lhs instanceof PySequenceExpression) lhs_tuple = (PySequenceExpression)lhs; else if (lhs != null) lhs_one = lhs; PySequenceExpression rhs_tuple = null; PyExpression rhs_one = null; if (rhs instanceof PyParenthesizedExpression) { PyExpression exp = ((PyParenthesizedExpression)rhs).getContainedExpression(); if (exp instanceof PyTupleExpression) rhs_tuple = (PySequenceExpression)exp; else rhs_one = rhs; } else if (rhs instanceof PySequenceExpression) rhs_tuple = (PySequenceExpression)rhs; else if (rhs != null) rhs_one = rhs; // if (lhs_one != null) { // single LHS, single RHS (direct mapping) or multiple RHS (packing) map.add(Pair.create(lhs_one, rhs)); } else if (lhs_tuple != null && rhs_one != null) { // multiple LHS, single RHS: unpacking // PY-2648, PY-2649 PyElementGenerator elementGenerator = PyElementGenerator.getInstance(rhs_one.getProject()); final LanguageLevel languageLevel = LanguageLevel.forElement(lhs); int counter = 0; for (PyExpression tuple_elt : lhs_tuple.getElements()) { try { final PyExpression expression = elementGenerator.createExpressionFromText(languageLevel, "(" + rhs_one.getText() + ")[" + counter + "]"); map.add(Pair.create(tuple_elt, expression)); } catch (IncorrectOperationException e) { // not parsed, no problem } ++counter; } } else if (lhs_tuple != null && rhs_tuple != null) { // multiple both sides: piecewise mapping final List<PyExpression> lhsTupleElements = Arrays.asList(lhs_tuple.getElements()); final List<PyExpression> rhsTupleElements = Arrays.asList(rhs_tuple.getElements()); final int size = Math.max(lhsTupleElements.size(), rhsTupleElements.size()); map.addAll(StreamEx.zip(alignToSize(lhsTupleElements, size), alignToSize(rhsTupleElements, size), Pair::create).toList()); } }