void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiElement defaultValue = descriptor.getPsiElement(); final PyNamedParameter param = PsiTreeUtil.getParentOfType(defaultValue, PyNamedParameter.class); final PyFunction function = PsiTreeUtil.getParentOfType(defaultValue, PyFunction.class); assert param != null; final String defName = param.getName(); if (function != null && defName != null) { final PyElementGenerator generator = PyElementGenerator.getInstance(project); final LanguageLevel languageLevel = LanguageLevel.forElement(function); final PyNamedParameter newParam = generator.createParameter(defName, PyNames.NONE, null, languageLevel); param.replace(newParam); final String conditionalText = "if " + defName + " is None:" + "\n\t" + defName + " = " + defaultValue.getText(); final PyIfStatement conditionalAssignment = generator.createFromText(languageLevel, PyIfStatement.class, conditionalText); PyPsiRefactoringUtil.addElementToStatementList(conditionalAssignment, function.getStatementList(), true); } }