PyUnresolvedReferencesVisitor (@NotNull PsiFile file) { final PsiFile contextFile = FileContextUtil.getContextFile(file); final PsiFile rfile = ObjectUtils.chooseNotNull(contextFile, file); TypeEvalContext context = TypeEvalContext.codeAnalysis(file.getProject(), rfile); SimplePyUnresolvedReferencesInspection inspection = new SimplePyUnresolvedReferencesInspection(); final PyUnresolvedReferencesVisitor visitor = new SimplePyUnresolvedReferencesInspection.Visitor(null, inspection, context); file.accept(new PyRecursiveElementVisitor() { @Override public void visitElement(@NotNull PsiElement node) { super.visitElement(node); node.accept(visitor); } }); return visitor; }