PyKeywordArgument (@NotNull PyFile setupPy, @NotNull String requirementName, @NotNull LanguageLevel languageLevel) { final String keyword = PyPsiUtils.containsImport(setupPy, "setuptools") ? INSTALL_REQUIRES : REQUIRES; final String text = String.format("foo(%s=['%s'])", keyword, requirementName); final PyExpression generated = PyElementGenerator.getInstance(setupPy.getProject()).createExpressionFromText(languageLevel, text); if (generated instanceof PyCallExpression callExpression) { return Stream .of(callExpression.getArguments()) .filter(PyKeywordArgument.class::isInstance) .map(PyKeywordArgument.class::cast) .filter(kwarg -> keyword.equals(kwarg.getKeyword())) .findFirst() .orElse(null); } return null; }