boolean (PsiElement element) { final PyFunction function = PsiTreeUtil.getParentOfType(element, PyFunction.class); final PyForPart forPart = PsiTreeUtil.getParentOfType(element, PyForPart.class); if (forPart != null) { final PyExpression target = forPart.getTarget(); if (target instanceof PyTargetExpression && element.getText().equals(target.getName())) return false; } final PyStatement nonlocalStatement = PsiTreeUtil.getParentOfType(element, PyNonlocalStatement.class, PyGlobalStatement.class); final PyStatementList statementList = PsiTreeUtil.getParentOfType(element, PyStatementList.class); PyImportStatement importStatement = PsiTreeUtil.getParentOfType(element, PyImportStatement.class); return nonlocalStatement == null && importStatement == null && statementList != null && function != null; }