diff --git a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java index 003e2c1eb0f0..56c465762b3a 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java @@ -20,6 +20,7 @@ import com.intellij.navigation.ItemPresentation; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; @@ -187,14 +188,20 @@ public class PyNamedParameterImpl extends PyBaseElementImpl quotes = PyStringLiteralUtil.getQuotes(defaultValue.getText()); - if (quotes != null) { - representation = quotes.getFirst() + PyStringLiteralUtil.getStringValue(defaultValue) + quotes.getSecond(); - } + final Pair quotes = defaultValue instanceof PyStringLiteralExpression + ? PyStringLiteralUtil.getQuotes(defaultValue.getText()) + : null; + + sb.append("="); + if (quotes != null) { + final String value = ((PyStringLiteralExpression)defaultValue).getStringValue(); + sb.append(quotes.getFirst()); + StringUtil.escapeStringCharacters(value.length(), value, sb); + sb.append(quotes.getSecond()); + } + else { + sb.append(PyUtil.getReadableRepr(defaultValue, true)); } - sb.append("=").append(representation); } return sb.toString(); diff --git a/python/testData/paramInfo/EscapingInDefaultValue.py b/python/testData/paramInfo/EscapingInDefaultValue.py new file mode 100644 index 000000000000..0d08ab15c51d --- /dev/null +++ b/python/testData/paramInfo/EscapingInDefaultValue.py @@ -0,0 +1,5 @@ +def foo(p="\n", t="\t", r="\r"): + pass + + +foo() \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java b/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java index 457e516a943f..c06179c45d66 100644 --- a/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java +++ b/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java @@ -606,6 +606,13 @@ public class PyParameterInfoTest extends LightMarkedTestCase { ); } + // PY-23625 + public void testEscapingInDefaultValue() { + final int offset = loadTest(1).get("").getTextOffset(); + + feignCtrlP(offset).check("p: str=\"\\n\", t: str=\"\\t\", r: str=\"\\r\"", new String[]{"p: str=\"\\n\", "}); + } + /** * Imitates pressing of Ctrl+P; fails if results are not as expected. * @param offset offset of 'cursor' where Ctrl+P is pressed.