boolean (@Nullable PsiElement element) { if (element == null || element.getContainingFile().getVirtualFile() instanceof BackedVirtualFile) return false; if (element instanceof PyClass) { return PyUtil.isTopLevel(element); } else if (element instanceof PyFunction) { if (PyUtil.isTopLevel(element)) return true; PyClass containingClass = ((PyFunction)element).getContainingClass(); if (containingClass != null && PyUtil.isTopLevel(containingClass)) return true; } return false; }