@NotNull
  private static List<PyFunction> collectImplementationsOrOverloads(@NotNull PyFunction function,
                                                                    boolean implementations,
                                                                    @NotNull TypeEvalContext context) {
    final ScopeOwner owner = ScopeUtil.getScopeOwner(function);
    final String name = function.getName();

    final List<PyFunction> result = new ArrayList<>();

    final Processor<PyFunction> overloadsProcessor = f -> {
      if (name != null && name.equals(f.getName()) && implementations ^ isOverload(f, context)) {
        result.add(f);
      }
      return true;
    };

    if (owner instanceof PyClass cls) {
      if (name != null) {
        cls.visitMethods(overloadsProcessor, false, context);
      }
    }
    else if (owner instanceof PyFile file) {
      for (PyFunction f : file.getTopLevelFunctions()) {
        if (!overloadsProcessor.process(f)) {
          break;
        }
      }
    }

    return result;
  }
@NotNull
  private static List<PyFunction> collectImplementationsOrOverloads(@NotNull PyFunction function,
                                                                    boolean implementations,
                                                                    @NotNull TypeEvalContext context)