PyLoopStatement (@NotNull PsiElement element) { final PyLoopStatement loop = PsiTreeUtil.getParentOfType(element, PyLoopStatement.class, true, ScopeOwner.class); if (loop instanceof PyStatementWithElse && PsiTreeUtil.isAncestor(((PyStatementWithElse)loop).getElsePart(), element, true)) { return getCorrespondingLoopImpl(loop); } return loop; }