private static boolean expressionReferencesLocalName(@NotNull PyExpression assignedValue, @NotNull PyFunction function) {
    Collection<PyReferenceExpression> references = PsiTreeUtil.collectElementsOfType(assignedValue, PyReferenceExpression.class);
    for (PyReferenceExpression reference : references) {
      if (reference.isQualified()) continue;
      Collection<PsiElement> resolved = PyResolveUtil.resolveLocally(reference);
      if (resolved.isEmpty()) continue;
      if (ContainerUtil.exists(resolved, it -> it instanceof PyParameter && ((PyParameter)it).isSelf())) continue;
      if (ContainerUtil.exists(resolved, it -> function == ScopeUtil.getScopeOwner(it))) return true;
    }
    return false;
  }
private static boolean expressionReferencesLocalName(@NotNull PyExpression assignedValue, @NotNull PyFunction function)