boolean (@NotNull PyExceptPart guard) { final ScopeOwner owner = ScopeUtil.getScopeOwner(guard); if (owner == null) return false; final ControlFlow flow = ControlFlowCache.getControlFlow(owner); final Instruction[] instructions = flow.getInstructions(); final int start = ControlFlowUtil.findInstructionNumberByElement(instructions, guard.getExceptClass()); if (start <= 0) return false; final Ref<Boolean> canEscapeGuard = Ref.create(false); ControlFlowUtil.process(instructions, start, instruction -> { final PsiElement e = instruction.getElement(); if (e != null && !PsiTreeUtil.isAncestor(guard, e, true)) { canEscapeGuard.set(true); return false; } return true; }); return !canEscapeGuard.get(); }