PyFunction (@NotNull PyFunction method) { PyParameter[] parameters = method.getParameterList().getParameters(); if (parameters.length > 0) { parameters[0].delete(); } PyClass topmostClass = PsiTreeUtil.getTopmostParentOfType(method, PyClass.class); assert topmostClass != null; PsiElement copy = method.copy(); method.delete(); return (PyFunction)topmostClass.getParent().addBefore(copy, topmostClass); }