public static void transplantImportsFromSignature(@NotNull PyFunction sourceFunction, @NotNull PyFunction targetFunction) {
    Map<String, PyReferenceExpression> unresolvedNames = new HashMap<>();

    targetFunction.accept(new PyRecursiveElementVisitor() {
      @Override
      public void visitPyReferenceExpression(@NotNull PyReferenceExpression referenceExpression) {
        super.visitPyReferenceExpression(referenceExpression);
        if (!referenceExpression.isQualified() && referenceExpression.getReference().multiResolve(false).length == 0) {
          unresolvedNames.put(referenceExpression.getName(), referenceExpression);
        }
      }

      @Override
      public void visitPyStatementList(@NotNull PyStatementList pruned) {
      }
    });

    sourceFunction.accept(new PyRecursiveElementVisitor() {
      @Override
      public void visitPyReferenceExpression(@NotNull PyReferenceExpression referenceExpression) {
        super.visitPyReferenceExpression(referenceExpression);
        if (!referenceExpression.isQualified()) {
          PyReferenceExpression unresolvedReference = unresolvedNames.get(referenceExpression.getName());
          if (unresolvedReference != null) {
            rememberNamedReferences(referenceExpression);
            restoreReference(referenceExpression, unresolvedReference, PsiElement.EMPTY_ARRAY);
          }
        }
      }

      @Override
      public void visitPyStatementList(@NotNull PyStatementList pruned) {
      }
    });
  }
public static void transplantImportsFromSignature(@NotNull PyFunction sourceFunction, @NotNull PyFunction targetFunction)