private boolean resolvesToSameLocal(PsiElement element, String elementName, ScopeOwner ourScopeOwner, ScopeOwner theirScopeOwner) {
    final PsiElement ourContainer = findContainer(getElement());
    final PsiElement theirContainer = findContainer(element);
    if (ourContainer != null) {
      if (ourContainer == theirContainer && ourScopeOwner == theirScopeOwner) {
        return true;
      }
      if (PsiTreeUtil.isAncestor(theirContainer, ourContainer, true)) {
        if (ourContainer instanceof PyComprehensionElement && containsDeclaration((PyComprehensionElement)ourContainer, elementName)) {
            return false;
        }

        ScopeOwner owner = ourScopeOwner;
        while (owner != theirScopeOwner && owner != null) {
          if (ControlFlowCache.getScope(owner).containsDeclaration(elementName)) {
            return false;
          }
          owner = ScopeUtil.getScopeOwner(owner);
        }

        return true;
      }
    }
    return false;
  }
private boolean resolvesToSameLocal(PsiElement element, String elementName, ScopeOwner ourScopeOwner, ScopeOwner theirScopeOwner)