boolean (@NotNull Project project, Editor editor, PsiFile file) { if (!(file instanceof PyFile)) { return false; } InfoHolder info = InfoHolder.collect(getElementFromEditor(editor, file)); info.myModuleReference = null; final PsiElement position = file.findElementAt(editor.getCaretModel().getOffset()); info.myFromImportStatement = PsiTreeUtil.getParentOfType(position, PyFromImportStatement.class); PyPsiUtils.assertValid(info.myFromImportStatement); if (info.myFromImportStatement != null && !info.myFromImportStatement.isFromFuture()) { info.myRelativeLevel = info.myFromImportStatement.getRelativeLevel(); info.myModuleReference = info.myFromImportStatement.getImportSource(); if (info.myRelativeLevel > 0) { // make sure we aren't importing a module from the relative path for (PyImportElement import_element : info.myFromImportStatement.getImportElements()) { PyReferenceExpression ref = import_element.getImportReferenceExpression(); PyPsiUtils.assertValid(ref); if (ref != null) { PsiElement target = ref.getReference().resolve(); final TypeEvalContext context = TypeEvalContext.codeAnalysis(file.getProject(), file); if (target instanceof PyExpression && context.getType((PyExpression)target) instanceof PyModuleType) { return false; } } } } } if (info.myModuleReference != null) { info.myModuleName = PyPsiUtils.toPath(info.myModuleReference); } if (info.myModuleReference != null && info.myFromImportStatement != null) { setText(info.getText()); return true; } return false; }