mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-12825 Remove unused parameter: do not allow to remove last argument after star when refactoring function with keyword-only arguments
This commit is contained in:
@@ -297,9 +297,18 @@ public class PyUnusedLocalInspectionVisitor extends PyInspectionVisitor {
|
||||
}
|
||||
}
|
||||
}
|
||||
final LocalQuickFix[] fixes = mayBeField
|
||||
? new LocalQuickFix[] { new AddFieldQuickFix(name, name, containingClass.getName()) }
|
||||
: new LocalQuickFix[] { new PyRemoveParameterQuickFix() };
|
||||
boolean canRemove = !(PsiTreeUtil.getPrevSiblingOfType(element, PyParameter.class) instanceof PySingleStarParameter);
|
||||
|
||||
final LocalQuickFix[] fixes;
|
||||
if (mayBeField) {
|
||||
fixes = new LocalQuickFix[]{new AddFieldQuickFix(name, name, containingClass.getName())};
|
||||
}
|
||||
else if (canRemove) {
|
||||
fixes = new LocalQuickFix[]{new PyRemoveParameterQuickFix()};
|
||||
}
|
||||
else {
|
||||
fixes = LocalQuickFix.EMPTY_ARRAY;
|
||||
}
|
||||
registerWarning(element, PyBundle.message("INSP.unused.locals.parameter.isnot.used", name), fixes);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def f1(*, u<caret>p):
|
||||
pass
|
||||
@@ -15,10 +15,13 @@
|
||||
*/
|
||||
package com.jetbrains.python.quickFixes;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyQuickFixTestCase;
|
||||
import com.jetbrains.python.inspections.PyUnusedLocalInspection;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher;
|
||||
|
||||
@TestDataPath("$CONTENT_ROOT/../testData//quickFixes/PyRemoveParameterQuickFixTest/")
|
||||
public class PyRemoveParameterQuickFixTest extends PyQuickFixTestCase {
|
||||
@@ -34,4 +37,20 @@ public class PyRemoveParameterQuickFixTest extends PyQuickFixTestCase {
|
||||
public void testDocstring() {
|
||||
doQuickFixTest(PyUnusedLocalInspection.class, PyBundle.message("QFIX.NAME.remove.parameter"));
|
||||
}
|
||||
|
||||
public void testSingleStar() {
|
||||
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.PYTHON33);
|
||||
try {
|
||||
final String testFileName = getTestName(true);
|
||||
myFixture.enableInspections(PyUnusedLocalInspection.class);
|
||||
myFixture.configureByFile(testFileName + ".py");
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
final IntentionAction intentionAction = myFixture.getAvailableIntention(PyBundle.message("QFIX.NAME.remove.parameter"));
|
||||
assertNull(intentionAction);
|
||||
}
|
||||
finally {
|
||||
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user