void (@NotNull PsiElement installRequires, @NotNull String requirementName, @NotNull LanguageLevel languageLevel) { final PyElementGenerator generator = PyElementGenerator.getInstance(installRequires.getProject()); final PyExpression newRequirement = generator.createExpressionFromText(languageLevel, "'" + requirementName + "'"); if (installRequires instanceof PyListLiteralExpression) { installRequires.add(newRequirement); } else if (installRequires instanceof PyTupleExpression) { final String newInstallRequiresText = StreamEx .of(((PyTupleExpression)installRequires).getElements()) .append(newRequirement) .map(PyExpression::getText) .joining(",", "(", ")"); final PyExpression expression = generator.createExpressionFromText(languageLevel, newInstallRequiresText); Optional .ofNullable(PyUtil.as(expression, PyParenthesizedExpression.class)) .map(PyParenthesizedExpression::getContainedExpression) .map(e -> PyUtil.as(e, PyTupleExpression.class)) .ifPresent(e -> installRequires.replace(e)); } else if (installRequires instanceof PyStringLiteralExpression) { final PyListLiteralExpression newInstallRequires = generator.createListLiteral(); newInstallRequires.add(installRequires); newInstallRequires.add(newRequirement); installRequires.replace(newInstallRequires); } }