PyReferenceExpression (@NotNull PyForStatement forLoop) { final PyForPart forPart = forLoop.getForPart(); if (forLoop.getElsePart() == null) { final PyStatement[] statements = forPart.getStatementList().getStatements(); if (statements.length == 1) { final PyStatement firstStmt = statements[0]; if (firstStmt instanceof PyExpressionStatement) { final PyExpression firstExpr = ((PyExpressionStatement)firstStmt).getExpression(); if (firstExpr instanceof PyYieldExpression yieldExpr) { final PyExpression yieldValue = yieldExpr.getExpression(); if (yieldValue instanceof PyReferenceExpression) { return (PyReferenceExpression)yieldValue; } } } } } return null; }