diff --git a/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java b/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java index a16636998e1d..91486933e582 100644 --- a/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java +++ b/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java @@ -14,7 +14,6 @@ import com.jetbrains.python.PyNames; import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.PythonFileType; import com.jetbrains.python.psi.PyFunction; -import com.jetbrains.python.psi.PyStringLiteralExpression; import com.jetbrains.python.psi.PyUtil; /** @@ -55,7 +54,13 @@ public class PyMethodNameTypedHandler extends TypedHandlerDelegate { else if (flags.isStaticMethod()) pname=""; documentManager.commitDocument(document); // TODO: only print the ")" if Settings require it - EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, "("+pname+"):", true); + int caretOffset = editor.getCaretModel().getOffset(); + String textToType = "(" + pname + ")"; + CharSequence chars = editor.getDocument().getCharsSequence(); + if (caretOffset == chars.length() || chars.charAt(caretOffset) != ':') { + textToType += ':'; + } + EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, textToType, true); editor.getCaretModel().moveToOffset(offset + 1 + pname.length()); // right after param name return Result.STOP; } diff --git a/python/testData/editing/firstParamDuplicateColon.after.py b/python/testData/editing/firstParamDuplicateColon.after.py new file mode 100644 index 000000000000..902d48453bff --- /dev/null +++ b/python/testData/editing/firstParamDuplicateColon.after.py @@ -0,0 +1,2 @@ +class C: + def someDefName(self): \ No newline at end of file diff --git a/python/testData/editing/firstParamDuplicateColon.py b/python/testData/editing/firstParamDuplicateColon.py new file mode 100644 index 000000000000..2945e1464cf2 --- /dev/null +++ b/python/testData/editing/firstParamDuplicateColon.py @@ -0,0 +1,2 @@ +class C: + def someDefName: \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyEditingTest.java b/python/testSrc/com/jetbrains/python/PyEditingTest.java index 9e4bde1d236a..9333a685c1fb 100644 --- a/python/testSrc/com/jetbrains/python/PyEditingTest.java +++ b/python/testSrc/com/jetbrains/python/PyEditingTest.java @@ -233,4 +233,8 @@ public class PyEditingTest extends PyLightFixtureTestCase { public void testFirstParamStaticmethod() { doTypingTest('('); } + + public void testFirstParamDuplicateColon() { // PY-2652 + doTypingTest('('); + } }