PY-15867 Omit single star parameter in updated constructor signature if it's not followed by keyword-only parameters

This commit is contained in:
Mikhail Golubev
2015-07-01 14:31:29 +03:00
parent ac8edc6465
commit 8c2d7c1190
6 changed files with 59 additions and 0 deletions
@@ -208,15 +208,21 @@ public class AddCallSuperQuickFix implements LocalQuickFix {
}
// Required keyword-only parameters
boolean hasKeywordOnlyParams = false;
for (PyParameter param : origInfo.getRequiredKeywordOnlyParameters()) {
newFunctionParams.add(param.getText());
hasKeywordOnlyParams = true;
}
for (PyParameter param : superInfo.getRequiredKeywordOnlyParameters()) {
if (!origInfo.getAllParameterNames().contains(param.getName())) {
newFunctionParams.add(param.getText());
hasKeywordOnlyParams = true;
}
superCallArgs.add(param.getName() + "=" + param.getName());
}
if (starredParam instanceof PySingleStarParameter && !hasKeywordOnlyParams) {
newFunctionParams.remove(newFunctionParams.size() - 1);
}
// Optional keyword-only parameters
for (PyParameter param : origInfo.getOptionalKeywordOnlyParameters()) {
@@ -0,0 +1,8 @@
class A:
def __init__(self, a, b=1, *, kw_only=2):
pass
class B(A):
def <warning descr="Call to __init__ of super class is missed">__i<caret>nit__</warning>(self):
pass
@@ -0,0 +1,8 @@
class A:
def __init__(self, a, b=1, *, kw_only=2):
pass
class B(A):
def __init__(self, a):
super().__init__(a)
@@ -0,0 +1,8 @@
class A:
def __init__(self, *, a):
pass
class B(A):
def <warning descr="Call to __init__ of super class is missed">__i<caret>nit__</warning>(self, a):
pass
@@ -0,0 +1,8 @@
class A:
def __init__(self, *, a):
pass
class B(A):
def __init__(self, a):
super().__init__(a=a)
@@ -115,6 +115,27 @@ public class Py3QuickFixTest extends PyTestCase {
doInspectionTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"), true, true);
}
// PY-15867
public void testAddCallSuperNoRequiredKeywordOnlyParamAfterSingleStarInSuperInit() {
runWithLanguageLevel(LanguageLevel.PYTHON30, new Runnable() {
@Override
public void run() {
doInspectionTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"), true, true);
}
});
}
// PY-15867
public void testAddCallSuperRequiredKeywordOnlyParamAfterSingleStarInSuperInitIsMerged() {
runWithLanguageLevel(LanguageLevel.PYTHON30, new Runnable() {
@Override
public void run() {
doInspectionTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"), true, true);
}
});
}
// PY-8991
public void testRemoveUnicodePrefixFromGluedStringNodesWithSlash() {
runWithLanguageLevel(LanguageLevel.PYTHON32, new Runnable() {