PointInImport (@NotNull PsiElement element) { final PsiElement parent = PsiTreeUtil.getNonStrictParentOfType(element, PyImportElement.class, PyFromImportStatement.class); if (parent instanceof PyFromImportStatement) { return PointInImport.AS_MODULE; // from foo ... } if (parent instanceof PyImportElement) { final PsiElement statement = parent.getParent(); if (statement instanceof PyImportStatement) { return PointInImport.AS_MODULE; // import foo,... } else if (statement instanceof PyFromImportStatement) { return PointInImport.AS_NAME; } } return PointInImport.NONE; }