private void checkNotReDeclaringUpperLoopOrStatement(@NotNull final PsiElement statement) {
      for (PyExpression declaredVar : getNamedElementsOfForAndWithStatements(statement)) {
        final Filter filter = new Filter(handleSubscriptionsAndResolveSafely(declaredVar));
        final PsiElement firstParent = PsiTreeUtil.findFirstParent(statement, true, filter);
        if ((firstParent != null) && isRequiredStatement(firstParent)) {
          // If parent is "for", we need to check that statement not declared in "else": PY-12367
          if ((firstParent instanceof PyForStatement) && isDeclaredInElse(statement, (PyForStatement)firstParent)) {
            continue;
          }
          registerProblem(declaredVar,
                          PyPsiBundle.message("INSP.assignment.to.loop.or.with.parameter", declaredVar.getText()));
        }
      }
    }
private void checkNotReDeclaringUpperLoopOrStatement(@NotNull final PsiElement statement)