PyFunction (@NotNull PyClass cls, @NotNull PyFunction baseFunction, @Nullable PsiElement anchor, boolean implement) { final PyStatementList statementList = cls.getStatementList(); final TypeEvalContext context = TypeEvalContext.userInitiated(cls.getProject(), cls.getContainingFile()); final PyFunction function = buildOverriddenFunction(cls, baseFunction, implement).addFunctionAfter(statementList, anchor); PyClassRefactoringUtil.transplantImportsFromSignature(baseFunction, function); PyiUtil .getOverloads(baseFunction, context) .forEach( baseOverload -> { final PyFunction overload = (PyFunction)statementList.addBefore(baseOverload, function); PyClassRefactoringUtil.transplantImportsFromSignature(baseOverload, overload); } ); return CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(function); }