From a249d4eda3840b92dc72ea872b4b820b291713c5 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Thu, 8 May 2014 13:30:57 +0400 Subject: [PATCH] fixed PY-12825 Remove unused parameter: do not allow to remove last argument after star when refactoring function with keyword-only arguments --- .../inspections/PyUnusedLocalInspectionVisitor.java | 3 ++- .../PyRemoveParameterQuickFixTest/singleStarTwoParam.py | 8 ++++++++ .../singleStarTwoParam_after.py | 6 ++++++ .../python/quickFixes/PyRemoveParameterQuickFixTest.java | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 python/testData/quickFixes/PyRemoveParameterQuickFixTest/singleStarTwoParam.py create mode 100644 python/testData/quickFixes/PyRemoveParameterQuickFixTest/singleStarTwoParam_after.py diff --git a/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java b/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java index a025521bc240..fab75bed993c 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java +++ b/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java @@ -297,7 +297,8 @@ public class PyUnusedLocalInspectionVisitor extends PyInspectionVisitor { } } } - boolean canRemove = !(PsiTreeUtil.getPrevSiblingOfType(element, PyParameter.class) instanceof PySingleStarParameter); + boolean canRemove = !(PsiTreeUtil.getPrevSiblingOfType(element, PyParameter.class) instanceof PySingleStarParameter) || + PsiTreeUtil.getNextSiblingOfType(element, PyParameter.class) != null; final LocalQuickFix[] fixes; if (mayBeField) { diff --git a/python/testData/quickFixes/PyRemoveParameterQuickFixTest/singleStarTwoParam.py b/python/testData/quickFixes/PyRemoveParameterQuickFixTest/singleStarTwoParam.py new file mode 100644 index 000000000000..21116ae4b229 --- /dev/null +++ b/python/testData/quickFixes/PyRemoveParameterQuickFixTest/singleStarTwoParam.py @@ -0,0 +1,8 @@ +def f1(*, up, another): + """ + :param up: my param + :type up: int + :rtype: int + + """ + print(another) \ No newline at end of file diff --git a/python/testData/quickFixes/PyRemoveParameterQuickFixTest/singleStarTwoParam_after.py b/python/testData/quickFixes/PyRemoveParameterQuickFixTest/singleStarTwoParam_after.py new file mode 100644 index 000000000000..998a21d74a93 --- /dev/null +++ b/python/testData/quickFixes/PyRemoveParameterQuickFixTest/singleStarTwoParam_after.py @@ -0,0 +1,6 @@ +def f1(*, another): + """ + :rtype: int + + """ + print(another) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/quickFixes/PyRemoveParameterQuickFixTest.java b/python/testSrc/com/jetbrains/python/quickFixes/PyRemoveParameterQuickFixTest.java index 092ee97e98fa..b162a1ebfd1c 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/PyRemoveParameterQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/quickFixes/PyRemoveParameterQuickFixTest.java @@ -42,6 +42,10 @@ public class PyRemoveParameterQuickFixTest extends PyQuickFixTestCase { doQuickFixTest(PyUnusedLocalInspection.class, PyBundle.message("QFIX.NAME.remove.parameter")); } + public void testSingleStarTwoParam() { + doQuickFixTest(PyUnusedLocalInspection.class, PyBundle.message("QFIX.NAME.remove.parameter"), LanguageLevel.PYTHON33); + } + public void testSingleStar() { PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.PYTHON33); try {