PyExceptPart (PyElement node) { final PyImportStatementBase importStatement = PsiTreeUtil.getParentOfType(node, PyImportStatementBase.class); if (importStatement != null) { final PyTryPart tryPart = PsiTreeUtil.getParentOfType(node, PyTryPart.class); if (tryPart != null) { final PyTryExceptStatement tryExceptStatement = PsiTreeUtil.getParentOfType(tryPart, PyTryExceptStatement.class); if (tryExceptStatement != null) { for (PyExceptPart exceptPart : tryExceptStatement.getExceptParts()) { final PyExpression expr = exceptPart.getExceptClass(); if (expr != null && "ImportError".equals(expr.getName())) { return exceptPart; } } } } } return null; }