PsiElement (PsiElement context) { if (PsiTreeUtil.getParentOfType(context, PyStatementList.class, false, ScopeOwner.class) != null || PsiTreeUtil.getParentOfType(context, PyFunction.class, PyClass.class) == null) { return super.getContainer(context); } return null; }