void (@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); final PyExceptPart part = PsiTreeUtil.getParentOfType(element, PyExceptPart.class); if (part == null) return; final PyExpression exceptClassExpression = part.getExceptClass(); if (exceptClassExpression == null) return; final var resolveContext = PyResolveContext.defaultContext(TypeEvalContext.codeInsightFallback(project)); final PsiElement exceptClass = ((PyReferenceExpression)exceptClassExpression).followAssignmentsChain(resolveContext).getElement(); if (exceptClass instanceof PyClass) { final PyTryExceptStatement statement = PsiTreeUtil.getParentOfType(part, PyTryExceptStatement.class); if (statement == null) return; PyExceptPart prevExceptPart = PsiTreeUtil.getPrevSiblingOfType(part, PyExceptPart.class); final ArrayList<PyClass> superClasses = Lists.newArrayList(((PyClass)exceptClass).getSuperClasses(null)); while (prevExceptPart != null) { final PyExpression classExpression = prevExceptPart.getExceptClass(); if (classExpression == null) return; final PsiElement aClass = ((PyReferenceExpression)classExpression).followAssignmentsChain(resolveContext).getElement(); if (aClass instanceof PyClass) { if (superClasses.contains(aClass)) { statement.addBefore(part, prevExceptPart); part.delete(); return; } } prevExceptPart = PsiTreeUtil.getPrevSiblingOfType(prevExceptPart, PyExceptPart.class); } } }