Ref<PyExpression> (@NotNull PyExpression listTupleExpr, int index) { boolean noElementsForSure = true; int seenElementsNumber = 0; PyExpression[] elements = getElementsFromListOrTuple(listTupleExpr); for (PyExpression element : elements) { if (element instanceof PyStarExpression) { if (!LanguageLevel.forElement(element).isAtLeast(LanguageLevel.PYTHON35)) continue; final PyExpression underStarExpr = PyPsiUtils.flattenParens(((PyStarExpression)element).getExpression()); if (PsiTreeUtil.instanceOf(underStarExpr, PyListLiteralExpression.class, PyTupleExpression.class)) { PyExpression[] subSequenceElements = getElementsFromListOrTuple(underStarExpr); int subsequenceElementIndex = index - seenElementsNumber; if (subsequenceElementIndex < subSequenceElements.length) { return Ref.create(subSequenceElements[subsequenceElementIndex]); } if (noElementsForSure) noElementsForSure = !ContainerUtil.exists(subSequenceElements, it -> it instanceof PyStarExpression); seenElementsNumber += subSequenceElements.length; } else { noElementsForSure = false; break; } } else { if (index == seenElementsNumber) { return Ref.create(element); } seenElementsNumber++; } } return noElementsForSure ? Ref.create() : null; }